[#294] aclsvc: Refactor checker 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 10:05:09 +03:00 committed by Evgenii Stratonikov
parent 7da284f3e8
commit 61541eaec2
3 changed files with 20 additions and 57 deletions

View file

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

View file

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

View file

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