[#294] aclsvcv2: Refactor service constructor

Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-07-06 11:44:37 +03:00 committed by Evgenii Stratonikov
parent 18d8898b00
commit 70a1081988
3 changed files with 23 additions and 72 deletions

View file

@ -421,20 +421,16 @@ func createACLServiceV2(c *cfg, splitSvc *objectService.TransportSplitter) v2.Se
irFetcher := createInnerRingFetcher(c) irFetcher := createInnerRingFetcher(c)
return v2.New( return v2.New(
v2.WithLogger(c.log), splitSvc,
v2.WithIRFetcher(newCachedIRFetcher(irFetcher)), c.netMapSource,
v2.WithNetmapSource(c.netMapSource), newCachedIRFetcher(irFetcher),
v2.WithContainerSource(
c.cfgObject.cnrSource,
),
v2.WithNextService(splitSvc),
v2.WithEACLChecker(
acl.NewChecker( acl.NewChecker(
c.cfgNetmap.state, c.cfgNetmap.state,
c.cfgObject.eaclSource, c.cfgObject.eaclSource,
eaclSDK.NewValidator(), eaclSDK.NewValidator(),
ls), ls),
), c.cfgObject.cnrSource,
v2.WithLogger(c.log),
) )
} }

View file

@ -1,9 +1,6 @@
package v2 package v2
import ( 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" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
) )
@ -13,39 +10,3 @@ func WithLogger(v *logger.Logger) Option {
c.log = v 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
}
}

View file

@ -73,32 +73,26 @@ type cfg struct {
next object.ServiceServer next object.ServiceServer
} }
func defaultCfg() *cfg {
return &cfg{
log: &logger.Logger{Logger: zap.L()},
}
}
// New is a constructor for object ACL checking service. // New is a constructor for object ACL checking service.
func New(opts ...Option) Service { func New(next object.ServiceServer,
cfg := defaultCfg() 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 { for i := range opts {
opts[i](cfg) 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{ return Service{
cfg: cfg, cfg: cfg,
c: senderClassifier{ c: senderClassifier{