[#384] Add check of Notificator interface value

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-03-25 15:13:54 +04:00 committed by Kirillov Denis
parent f0914b8a43
commit 83bb6fc020
3 changed files with 11 additions and 20 deletions

View file

@ -281,10 +281,6 @@ func (n *layer) EphemeralKey() *keys.PublicKey {
} }
func (n *layer) Initialize(ctx context.Context, c Notificator) error { func (n *layer) Initialize(ctx context.Context, c Notificator) error {
if c == nil {
return nil
}
if n.IsNotificationEnabled() { if n.IsNotificationEnabled() {
return fmt.Errorf("already initialized") return fmt.Errorf("already initialized")
} }

View file

@ -37,10 +37,6 @@ type Stream struct {
} }
func NewController(p *Options, l *zap.Logger) (*Controller, error) { func NewController(p *Options, l *zap.Logger) (*Controller, error) {
if p == nil {
return nil, nil
}
ncopts := []nats.Option{ ncopts := []nats.Option{
nats.Timeout(p.Timeout), nats.Timeout(p.Timeout),
} }

View file

@ -57,6 +57,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App {
caller api.Handler caller api.Handler
ctr auth.Center ctr auth.Center
obj layer.Client obj layer.Client
nc *notifications.Controller
poolPeers = fetchPeers(l, v) 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)) 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{ layerCfg := &layer.Config{
Caches: getCacheOptions(v, l), Caches: getCacheOptions(v, l),
AnonKey: layer.AnonymousKey{ AnonKey: layer.AnonymousKey{
@ -160,9 +155,17 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App {
// prepare object layer // prepare object layer
obj = layer.NewLayer(l, &layerNeoFS{&neoFS}, layerCfg) obj = layer.NewLayer(l, &layerNeoFS{&neoFS}, layerCfg)
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 { if err = obj.Initialize(ctx, nc); err != nil {
l.Fatal("couldn't initialize layer", zap.Error(err)) l.Fatal("couldn't initialize layer", zap.Error(err))
} }
}
// prepare auth center // prepare auth center
ctr = auth.New(&neofs.AuthmateNeoFS{ ctr = auth.New(&neofs.AuthmateNeoFS{
@ -265,10 +268,6 @@ func (a *App) Server(ctx context.Context) {
} }
func getNotificationsOptions(v *viper.Viper, l *zap.Logger) *notifications.Options { func getNotificationsOptions(v *viper.Viper, l *zap.Logger) *notifications.Options {
if enabled := v.GetBool(cfgEnableNATS); !enabled {
return nil
}
cfg := notifications.Options{} cfg := notifications.Options{}
cfg.URL = v.GetString(cfgNATSEndpoint) cfg.URL = v.GetString(cfgNATSEndpoint)
cfg.Timeout = v.GetDuration(cfgNATSTimeout) cfg.Timeout = v.GetDuration(cfgNATSTimeout)