From e0c654456767d837973c75351667ad97791e6ddf Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Tue, 8 Feb 2022 18:34:31 +0300 Subject: [PATCH] [#340] Move notification controller to layer Signed-off-by: Angira Kekteeva --- api/layer/layer.go | 16 ++++++++++++---- cmd/s3-gw/app.go | 5 ++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index c88339d73..6c710785a 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -15,6 +15,7 @@ import ( "github.com/nspcc-dev/neofs-s3-gw/api/cache" "github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/errors" + "github.com/nspcc-dev/neofs-s3-gw/api/notifications" "github.com/nspcc-dev/neofs-s3-gw/api/resolver" "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" "github.com/nspcc-dev/neofs-sdk-go/client" @@ -34,6 +35,7 @@ type ( log *zap.Logger anonKey AnonymousKey resolver *resolver.BucketResolver + ncontroller *notifications.Controller listsCache *cache.ObjectsListCache objCache *cache.ObjectsCache namesCache *cache.ObjectsNameCache @@ -42,10 +44,11 @@ type ( } Config struct { - ChainAddress string - Caches *CachesConfig - AnonKey AnonymousKey - Resolver *resolver.BucketResolver + ChainAddress string + Caches *CachesConfig + AnonKey AnonymousKey + Resolver *resolver.BucketResolver + NotificationController *notifications.Controller } // AnonymousKey contains data for anonymous requests. @@ -264,6 +267,7 @@ func NewLayer(log *zap.Logger, conns pool.Pool, config *Config) Client { anonKey: config.AnonKey, resolver: config.Resolver, listsCache: cache.NewObjectsListCache(config.Caches.ObjectsList), + ncontroller: config.NotificationController, objCache: cache.New(config.Caches.Objects), namesCache: cache.NewObjectsNameCache(config.Caches.Names), bucketCache: cache.NewBucketCache(config.Caches.Buckets), @@ -275,6 +279,10 @@ func (n *layer) EphemeralKey() *keys.PublicKey { return n.anonKey.Key.PublicKey() } +func (n *layer) IsNotificationEnabled() bool { + return n.ncontroller != nil +} + // IsAuthenticatedRequest check if access box exists in current request. func IsAuthenticatedRequest(ctx context.Context) bool { _, ok := ctx.Value(api.BoxData).(*accessbox.Box) diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index f2f076fd3..a8a5eb8ef 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -36,7 +36,6 @@ type ( tls *tlsConfig obj layer.Client api api.Handler - nc *notifications.Controller maxClients api.MaxClients @@ -154,7 +153,8 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { AnonKey: layer.AnonymousKey{ Key: randomKey, }, - Resolver: bucketResolver, + Resolver: bucketResolver, + NotificationController: nc, } // prepare object layer @@ -177,7 +177,6 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { obj: obj, tls: tls, api: caller, - nc: nc, webDone: make(chan struct{}, 1), wrkDone: make(chan struct{}, 1),