From 70a108198884211b35f10b1a196eefe3234e56ef Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Jul 2023 11:44:37 +0300 Subject: [PATCH] [#294] aclsvcv2: Refactor service constructor Pass required deps as args. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/object.go | 22 +++++++-------- pkg/services/object/acl/v2/opts.go | 39 --------------------------- pkg/services/object/acl/v2/service.go | 34 ++++++++++------------- 3 files changed, 23 insertions(+), 72 deletions(-) diff --git a/cmd/frostfs-node/object.go b/cmd/frostfs-node/object.go index 45b1089a7..da7458170 100644 --- a/cmd/frostfs-node/object.go +++ b/cmd/frostfs-node/object.go @@ -421,20 +421,16 @@ func createACLServiceV2(c *cfg, splitSvc *objectService.TransportSplitter) v2.Se irFetcher := createInnerRingFetcher(c) return v2.New( + splitSvc, + c.netMapSource, + newCachedIRFetcher(irFetcher), + acl.NewChecker( + c.cfgNetmap.state, + c.cfgObject.eaclSource, + eaclSDK.NewValidator(), + ls), + c.cfgObject.cnrSource, v2.WithLogger(c.log), - v2.WithIRFetcher(newCachedIRFetcher(irFetcher)), - v2.WithNetmapSource(c.netMapSource), - v2.WithContainerSource( - c.cfgObject.cnrSource, - ), - v2.WithNextService(splitSvc), - v2.WithEACLChecker( - acl.NewChecker( - c.cfgNetmap.state, - c.cfgObject.eaclSource, - eaclSDK.NewValidator(), - ls), - ), ) } diff --git a/pkg/services/object/acl/v2/opts.go b/pkg/services/object/acl/v2/opts.go index 7e937da06..15fcce884 100644 --- a/pkg/services/object/acl/v2/opts.go +++ b/pkg/services/object/acl/v2/opts.go @@ -1,9 +1,6 @@ package v2 import ( - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap" - objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" ) @@ -13,39 +10,3 @@ func WithLogger(v *logger.Logger) Option { c.log = v } } - -// WithNetmapSource return option to set -// netmap source. -func WithNetmapSource(v netmap.Source) Option { - return func(c *cfg) { - c.nm = v - } -} - -// WithContainerSource returns option to set container source. -func WithContainerSource(v container.Source) Option { - return func(c *cfg) { - c.containers = v - } -} - -// WithNextService returns option to set next object service. -func WithNextService(v objectSvc.ServiceServer) Option { - return func(c *cfg) { - c.next = v - } -} - -// WithEACLChecker returns option to set eACL checker. -func WithEACLChecker(v ACLChecker) Option { - return func(c *cfg) { - c.checker = v - } -} - -// WithIRFetcher returns option to set inner ring fetcher. -func WithIRFetcher(v InnerRingFetcher) Option { - return func(c *cfg) { - c.irFetcher = v - } -} diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index c75bd326f..412708b1c 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -73,32 +73,26 @@ type cfg struct { next object.ServiceServer } -func defaultCfg() *cfg { - return &cfg{ - log: &logger.Logger{Logger: zap.L()}, - } -} - // New is a constructor for object ACL checking service. -func New(opts ...Option) Service { - cfg := defaultCfg() +func New(next object.ServiceServer, + nm netmap.Source, + irf InnerRingFetcher, + acl ACLChecker, + cs container.Source, + opts ...Option) Service { + cfg := &cfg{ + log: &logger.Logger{Logger: zap.L()}, + next: next, + nm: nm, + irFetcher: irf, + checker: acl, + containers: cs, + } for i := range opts { opts[i](cfg) } - panicOnNil := func(v any, name string) { - if v == nil { - panic(fmt.Sprintf("ACL service: %s is nil", name)) - } - } - - panicOnNil(cfg.next, "next Service") - panicOnNil(cfg.nm, "netmap client") - panicOnNil(cfg.irFetcher, "inner Ring fetcher") - panicOnNil(cfg.checker, "acl checker") - panicOnNil(cfg.containers, "container source") - return Service{ cfg: cfg, c: senderClassifier{