From 61541eaec2c0feab381b57dc512a6380395c7b2f Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Jul 2023 10:05:09 +0300 Subject: [PATCH] [#294] aclsvc: Refactor checker constructor Pass required deps as args. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/object.go | 11 +++--- pkg/services/object/acl/acl.go | 55 ++++++----------------------- pkg/services/object/acl/acl_test.go | 11 +++--- 3 files changed, 20 insertions(+), 57 deletions(-) diff --git a/cmd/frostfs-node/object.go b/cmd/frostfs-node/object.go index 1d99d958b..45b1089a7 100644 --- a/cmd/frostfs-node/object.go +++ b/cmd/frostfs-node/object.go @@ -429,12 +429,11 @@ func createACLServiceV2(c *cfg, splitSvc *objectService.TransportSplitter) v2.Se ), v2.WithNextService(splitSvc), v2.WithEACLChecker( - acl.NewChecker(new(acl.CheckerPrm). - SetNetmapState(c.cfgNetmap.state). - SetEACLSource(c.cfgObject.eaclSource). - SetValidator(eaclSDK.NewValidator()). - SetLocalStorage(ls), - ), + acl.NewChecker( + c.cfgNetmap.state, + c.cfgObject.eaclSource, + eaclSDK.NewValidator(), + ls), ), ) } diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index 351b4ad3b..cfe49396e 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -21,35 +21,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" ) -// CheckerPrm groups parameters for Checker -// constructor. -type CheckerPrm struct { - eaclSrc container.EACLSource - validator *eaclSDK.Validator - localStorage *engine.StorageEngine - state netmap.State -} - -func (c *CheckerPrm) SetEACLSource(v container.EACLSource) *CheckerPrm { - c.eaclSrc = v - return c -} - -func (c *CheckerPrm) SetValidator(v *eaclSDK.Validator) *CheckerPrm { - c.validator = v - return c -} - -func (c *CheckerPrm) SetLocalStorage(v *engine.StorageEngine) *CheckerPrm { - c.localStorage = v - return c -} - -func (c *CheckerPrm) SetNetmapState(v netmap.State) *CheckerPrm { - c.state = v - return c -} - // Checker implements v2.ACLChecker interfaces and provides // ACL/eACL validation functionality. type Checker struct { @@ -71,23 +42,17 @@ var ( // NewChecker creates Checker. // Panics if at least one of the parameter is nil. -func NewChecker(prm *CheckerPrm) *Checker { - panicOnNil := func(fieldName string, field any) { - if field == nil { - panic(fmt.Sprintf("incorrect field %s (%T): %v", fieldName, field, field)) - } - } - - panicOnNil("EACLSource", prm.eaclSrc) - panicOnNil("EACLValidator", prm.validator) - panicOnNil("LocalStorageEngine", prm.localStorage) - panicOnNil("NetmapState", prm.state) - +func NewChecker( + state netmap.State, + eaclSrc container.EACLSource, + validator *eaclSDK.Validator, + localStorage *engine.StorageEngine, +) *Checker { return &Checker{ - eaclSrc: prm.eaclSrc, - validator: prm.validator, - localStorage: prm.localStorage, - state: prm.state, + eaclSrc: eaclSrc, + validator: validator, + localStorage: localStorage, + state: state, } } diff --git a/pkg/services/object/acl/acl_test.go b/pkg/services/object/acl/acl_test.go index d3ad1e6fd..b9b82dac8 100644 --- a/pkg/services/object/acl/acl_test.go +++ b/pkg/services/object/acl/acl_test.go @@ -27,12 +27,11 @@ func (e emptyNetmapState) CurrentEpoch() uint64 { } func TestStickyCheck(t *testing.T) { - checker := NewChecker(new(CheckerPrm). - SetLocalStorage(&engine.StorageEngine{}). - SetValidator(eaclSDK.NewValidator()). - SetEACLSource(emptyEACLSource{}). - SetNetmapState(emptyNetmapState{}), - ) + checker := NewChecker( + emptyNetmapState{}, + emptyEACLSource{}, + eaclSDK.NewValidator(), + &engine.StorageEngine{}) t.Run("system role", func(t *testing.T) { var info v2.RequestInfo