Separate identity from server config (#1138)

This commit is contained in:
Egon Elbre 2019-01-25 16:54:54 +02:00 committed by GitHub
parent 143e6a58e9
commit 85b43926b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 21 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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() {

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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