From 85b43926b4d445cbc69177394c9702ae464acc82 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Fri, 25 Jan 2019 16:54:54 +0200 Subject: [PATCH] Separate identity from server config (#1138) --- bootstrap/peer.go | 2 ++ cmd/bootstrap/main.go | 4 ++-- cmd/certificates/main.go | 16 ++++++++++++---- cmd/satellite/main.go | 4 ++-- cmd/storagenode/main.go | 6 +++--- pkg/server/config.go | 12 ++---------- storagenode/peer.go | 2 ++ 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/bootstrap/peer.go b/bootstrap/peer.go index c4323cc18..08bf67dd7 100644 --- a/bootstrap/peer.go +++ b/bootstrap/peer.go @@ -34,6 +34,8 @@ type DB interface { // Config is all the configuration parameters for a Bootstrap Node type Config struct { + Identity identity.Config + Server server.Config Kademlia kademlia.Config } diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 8a733dc22..1229f7daa 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -79,7 +79,7 @@ func init() { func cmdRun(cmd *cobra.Command, args []string) (err error) { log := zap.L() - identity, err := runCfg.Server.Identity.Load() + identity, err := runCfg.Identity.Load() if err != nil { zap.S().Fatal(err) } @@ -90,7 +90,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) { } 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) } diff --git a/cmd/certificates/main.go b/cmd/certificates/main.go index 95b752c57..772c5f7ce 100644 --- a/cmd/certificates/main.go +++ b/cmd/certificates/main.go @@ -34,9 +34,12 @@ var ( config struct { batchCfg - CA identity.CASetupConfig - Identity identity.SetupConfig - Server server.Config + CA identity.CASetupConfig + Identity identity.SetupConfig + Server struct { // workaround server.Config change + Identity identity.Config + server.Config + } Signer certificates.CertServerConfig 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:"-"` @@ -74,7 +77,12 @@ func init() { func cmdRun(cmd *cobra.Command, args []string) error { 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() { diff --git a/cmd/satellite/main.go b/cmd/satellite/main.go index bcc895420..cd5d4ac31 100644 --- a/cmd/satellite/main.go +++ b/cmd/satellite/main.go @@ -111,13 +111,13 @@ func init() { func cmdRun(cmd *cobra.Command, args []string) (err error) { log := zap.L() - identity, err := runCfg.Server.Identity.Load() + identity, err := runCfg.Identity.Load() if err != nil { zap.S().Fatal(err) } 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) } diff --git a/cmd/storagenode/main.go b/cmd/storagenode/main.go index 793a62099..0ba99bcba 100644 --- a/cmd/storagenode/main.go +++ b/cmd/storagenode/main.go @@ -132,7 +132,7 @@ func init() { func cmdRun(cmd *cobra.Command, args []string) (err error) { log := zap.L() - identity, err := runCfg.Server.Identity.Load() + identity, err := runCfg.Identity.Load() if err != nil { zap.S().Fatal(err) } @@ -143,7 +143,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) { } 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) } @@ -332,7 +332,7 @@ func cmdDiag(cmd *cobra.Command, args []string) (err error) { func dashCmd(cmd *cobra.Command, args []string) (err error) { ctx := context.Background() - ident, err := runCfg.Server.Identity.Load() + ident, err := runCfg.Identity.Load() if err != nil { zap.S().Fatal(err) } else { diff --git a/pkg/server/config.go b/pkg/server/config.go index a98642aec..418d2dd77 100644 --- a/pkg/server/config.go +++ b/pkg/server/config.go @@ -22,27 +22,19 @@ type Config struct { UsePeerCAWhitelist bool `help:"if true, uses peer ca whitelist checking" default:"false"` Address string `user:"true" help:"address to listen on" default:":7777"` Extensions peertls.TLSExtConfig - - Identity identity.Config // TODO: separate identity } // Run will run the given responsibilities with the configured identity. -func (sc Config) Run(ctx context.Context, - interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) { +func (sc Config) Run(ctx context.Context, identity *identity.FullIdentity, interceptor grpc.UnaryServerInterceptor, services ...Service) (err error) { defer mon.Task()(&ctx)(&err) - ident, err := sc.Identity.Load() - if err != nil { - return err - } - lis, err := net.Listen("tcp", sc.Address) if err != nil { return err } defer func() { _ = lis.Close() }() - opts, err := NewOptions(ident, sc) + opts, err := NewOptions(identity, sc) if err != nil { return err } diff --git a/storagenode/peer.go b/storagenode/peer.go index 4a76ebb5f..8111d9597 100644 --- a/storagenode/peer.go +++ b/storagenode/peer.go @@ -40,6 +40,8 @@ type DB interface { // Config is all the configuration parameters for a Storage Node type Config struct { + Identity identity.Config + Server server.Config Kademlia kademlia.Config Storage psserver.Config