From 83bb6fc020d1afa085521f92d27315bccb8c7fc7 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Fri, 25 Mar 2022 15:13:54 +0400 Subject: [PATCH] [#384] Add check of Notificator interface value Signed-off-by: Angira Kekteeva --- api/layer/layer.go | 4 ---- api/notifications/controller.go | 4 ---- cmd/s3-gw/app.go | 23 +++++++++++------------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index fec8c09c..d0790162 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -281,10 +281,6 @@ func (n *layer) EphemeralKey() *keys.PublicKey { } func (n *layer) Initialize(ctx context.Context, c Notificator) error { - if c == nil { - return nil - } - if n.IsNotificationEnabled() { return fmt.Errorf("already initialized") } diff --git a/api/notifications/controller.go b/api/notifications/controller.go index 4bc3f0d5..8e754cd0 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -37,10 +37,6 @@ type Stream struct { } func NewController(p *Options, l *zap.Logger) (*Controller, error) { - if p == nil { - return nil, nil - } - ncopts := []nats.Option{ nats.Timeout(p.Timeout), } diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index 59645503..4ec4fc92 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -57,6 +57,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { caller api.Handler ctr auth.Center obj layer.Client + nc *notifications.Controller poolPeers = fetchPeers(l, v) @@ -143,12 +144,6 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { l.Fatal("failed to form resolver", zap.Error(err)) } - nopts := getNotificationsOptions(v, l) - nc, err := notifications.NewController(nopts, l) - if err != nil { - l.Fatal("failed to enable notifications", zap.Error(err)) - } - layerCfg := &layer.Config{ Caches: getCacheOptions(v, l), AnonKey: layer.AnonymousKey{ @@ -160,8 +155,16 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { // prepare object layer obj = layer.NewLayer(l, &layerNeoFS{&neoFS}, layerCfg) - if err = obj.Initialize(ctx, nc); err != nil { - l.Fatal("couldn't initialize layer", zap.Error(err)) + if v.GetBool(cfgEnableNATS) { + nopts := getNotificationsOptions(v, l) + nc, err = notifications.NewController(nopts, l) + if err != nil { + l.Fatal("failed to enable notifications", zap.Error(err)) + } + + if err = obj.Initialize(ctx, nc); err != nil { + l.Fatal("couldn't initialize layer", zap.Error(err)) + } } // prepare auth center @@ -265,10 +268,6 @@ func (a *App) Server(ctx context.Context) { } func getNotificationsOptions(v *viper.Viper, l *zap.Logger) *notifications.Options { - if enabled := v.GetBool(cfgEnableNATS); !enabled { - return nil - } - cfg := notifications.Options{} cfg.URL = v.GetString(cfgNATSEndpoint) cfg.Timeout = v.GetDuration(cfgNATSTimeout)