[#340] Move notification controller to layer

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-02-08 18:34:31 +03:00 committed by LeL
parent 8529a7d80b
commit e0c6544567
2 changed files with 14 additions and 7 deletions

View file

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

View file

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