Separate identity from server config (#1138)
This commit is contained in:
parent
143e6a58e9
commit
85b43926b4
@ -34,6 +34,8 @@ type DB interface {
|
|||||||
|
|
||||||
// Config is all the configuration parameters for a Bootstrap Node
|
// Config is all the configuration parameters for a Bootstrap Node
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Identity identity.Config
|
||||||
|
|
||||||
Server server.Config
|
Server server.Config
|
||||||
Kademlia kademlia.Config
|
Kademlia kademlia.Config
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func init() {
|
|||||||
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||||
log := zap.L()
|
log := zap.L()
|
||||||
|
|
||||||
identity, err := runCfg.Server.Identity.Load()
|
identity, err := runCfg.Identity.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Fatal(err)
|
zap.S().Fatal(err)
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := process.Ctx(cmd)
|
ctx := process.Ctx(cmd)
|
||||||
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Server.Identity.CertPath); err != nil {
|
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Identity.CertPath); err != nil {
|
||||||
zap.S().Errorf("Failed to initialize telemetry batcher: %+v", err)
|
zap.S().Errorf("Failed to initialize telemetry batcher: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +34,12 @@ var (
|
|||||||
|
|
||||||
config struct {
|
config struct {
|
||||||
batchCfg
|
batchCfg
|
||||||
CA identity.CASetupConfig
|
CA identity.CASetupConfig
|
||||||
Identity identity.SetupConfig
|
Identity identity.SetupConfig
|
||||||
Server server.Config
|
Server struct { // workaround server.Config change
|
||||||
|
Identity identity.Config
|
||||||
|
server.Config
|
||||||
|
}
|
||||||
Signer certificates.CertServerConfig
|
Signer certificates.CertServerConfig
|
||||||
All bool `help:"print the all authorizations for auth info/export subcommands" default:"false"`
|
All bool `help:"print the all authorizations for auth info/export subcommands" default:"false"`
|
||||||
Out string `help:"output file path for auth export subcommand; if \"-\", will use STDOUT" default:"-"`
|
Out string `help:"output file path for auth export subcommand; if \"-\", will use STDOUT" default:"-"`
|
||||||
@ -74,7 +77,12 @@ func init() {
|
|||||||
func cmdRun(cmd *cobra.Command, args []string) error {
|
func cmdRun(cmd *cobra.Command, args []string) error {
|
||||||
ctx := process.Ctx(cmd)
|
ctx := process.Ctx(cmd)
|
||||||
|
|
||||||
return config.Server.Run(ctx, nil, config.Signer)
|
identity, err := config.Server.Identity.Load()
|
||||||
|
if err != nil {
|
||||||
|
zap.S().Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Server.Run(ctx, identity, nil, config.Signer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -111,13 +111,13 @@ func init() {
|
|||||||
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||||
log := zap.L()
|
log := zap.L()
|
||||||
|
|
||||||
identity, err := runCfg.Server.Identity.Load()
|
identity, err := runCfg.Identity.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Fatal(err)
|
zap.S().Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := process.Ctx(cmd)
|
ctx := process.Ctx(cmd)
|
||||||
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Server.Identity.CertPath); err != nil {
|
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Identity.CertPath); err != nil {
|
||||||
zap.S().Errorf("Failed to initialize telemetry batcher: %+v", err)
|
zap.S().Errorf("Failed to initialize telemetry batcher: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func init() {
|
|||||||
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
||||||
log := zap.L()
|
log := zap.L()
|
||||||
|
|
||||||
identity, err := runCfg.Server.Identity.Load()
|
identity, err := runCfg.Identity.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Fatal(err)
|
zap.S().Fatal(err)
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := process.Ctx(cmd)
|
ctx := process.Ctx(cmd)
|
||||||
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Server.Identity.CertPath); err != nil {
|
if err := process.InitMetricsWithCertPath(ctx, nil, runCfg.Identity.CertPath); err != nil {
|
||||||
zap.S().Error("Failed to initialize telemetry batcher: ", err)
|
zap.S().Error("Failed to initialize telemetry batcher: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ func cmdDiag(cmd *cobra.Command, args []string) (err error) {
|
|||||||
func dashCmd(cmd *cobra.Command, args []string) (err error) {
|
func dashCmd(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ident, err := runCfg.Server.Identity.Load()
|
ident, err := runCfg.Identity.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Fatal(err)
|
zap.S().Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,27 +22,19 @@ type Config struct {
|
|||||||
UsePeerCAWhitelist bool `help:"if true, uses peer ca whitelist checking" default:"false"`
|
UsePeerCAWhitelist bool `help:"if true, uses peer ca whitelist checking" default:"false"`
|
||||||
Address string `user:"true" help:"address to listen on" default:":7777"`
|
Address string `user:"true" help:"address to listen on" default:":7777"`
|
||||||
Extensions peertls.TLSExtConfig
|
Extensions peertls.TLSExtConfig
|
||||||
|
|
||||||
Identity identity.Config // TODO: separate identity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run will run the given responsibilities with the configured identity.
|
// Run will run the given responsibilities with the configured identity.
|
||||||
func (sc Config) Run(ctx context.Context,
|
func (sc Config) Run(ctx context.Context, identity *identity.FullIdentity, interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) {
|
||||||
interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) {
|
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
ident, err := sc.Identity.Load()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", sc.Address)
|
lis, err := net.Listen("tcp", sc.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() { _ = lis.Close() }()
|
defer func() { _ = lis.Close() }()
|
||||||
|
|
||||||
opts, err := NewOptions(ident, sc)
|
opts, err := NewOptions(identity, sc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ type DB interface {
|
|||||||
|
|
||||||
// Config is all the configuration parameters for a Storage Node
|
// Config is all the configuration parameters for a Storage Node
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Identity identity.Config
|
||||||
|
|
||||||
Server server.Config
|
Server server.Config
|
||||||
Kademlia kademlia.Config
|
Kademlia kademlia.Config
|
||||||
Storage psserver.Config
|
Storage psserver.Config
|
||||||
|
Loading…
Reference in New Issue
Block a user