forked from TrueCloudLab/frostfs-node
[#294] aclsvc: Refactor checker constructor
Pass required deps as args. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
7da284f3e8
commit
61541eaec2
3 changed files with 20 additions and 57 deletions
|
@ -429,12 +429,11 @@ func createACLServiceV2(c *cfg, splitSvc *objectService.TransportSplitter) v2.Se
|
||||||
),
|
),
|
||||||
v2.WithNextService(splitSvc),
|
v2.WithNextService(splitSvc),
|
||||||
v2.WithEACLChecker(
|
v2.WithEACLChecker(
|
||||||
acl.NewChecker(new(acl.CheckerPrm).
|
acl.NewChecker(
|
||||||
SetNetmapState(c.cfgNetmap.state).
|
c.cfgNetmap.state,
|
||||||
SetEACLSource(c.cfgObject.eaclSource).
|
c.cfgObject.eaclSource,
|
||||||
SetValidator(eaclSDK.NewValidator()).
|
eaclSDK.NewValidator(),
|
||||||
SetLocalStorage(ls),
|
ls),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,35 +21,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"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
|
// Checker implements v2.ACLChecker interfaces and provides
|
||||||
// ACL/eACL validation functionality.
|
// ACL/eACL validation functionality.
|
||||||
type Checker struct {
|
type Checker struct {
|
||||||
|
@ -71,23 +42,17 @@ var (
|
||||||
|
|
||||||
// NewChecker creates Checker.
|
// NewChecker creates Checker.
|
||||||
// Panics if at least one of the parameter is nil.
|
// Panics if at least one of the parameter is nil.
|
||||||
func NewChecker(prm *CheckerPrm) *Checker {
|
func NewChecker(
|
||||||
panicOnNil := func(fieldName string, field any) {
|
state netmap.State,
|
||||||
if field == nil {
|
eaclSrc container.EACLSource,
|
||||||
panic(fmt.Sprintf("incorrect field %s (%T): %v", fieldName, field, field))
|
validator *eaclSDK.Validator,
|
||||||
}
|
localStorage *engine.StorageEngine,
|
||||||
}
|
) *Checker {
|
||||||
|
|
||||||
panicOnNil("EACLSource", prm.eaclSrc)
|
|
||||||
panicOnNil("EACLValidator", prm.validator)
|
|
||||||
panicOnNil("LocalStorageEngine", prm.localStorage)
|
|
||||||
panicOnNil("NetmapState", prm.state)
|
|
||||||
|
|
||||||
return &Checker{
|
return &Checker{
|
||||||
eaclSrc: prm.eaclSrc,
|
eaclSrc: eaclSrc,
|
||||||
validator: prm.validator,
|
validator: validator,
|
||||||
localStorage: prm.localStorage,
|
localStorage: localStorage,
|
||||||
state: prm.state,
|
state: state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,11 @@ func (e emptyNetmapState) CurrentEpoch() uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStickyCheck(t *testing.T) {
|
func TestStickyCheck(t *testing.T) {
|
||||||
checker := NewChecker(new(CheckerPrm).
|
checker := NewChecker(
|
||||||
SetLocalStorage(&engine.StorageEngine{}).
|
emptyNetmapState{},
|
||||||
SetValidator(eaclSDK.NewValidator()).
|
emptyEACLSource{},
|
||||||
SetEACLSource(emptyEACLSource{}).
|
eaclSDK.NewValidator(),
|
||||||
SetNetmapState(emptyNetmapState{}),
|
&engine.StorageEngine{})
|
||||||
)
|
|
||||||
|
|
||||||
t.Run("system role", func(t *testing.T) {
|
t.Run("system role", func(t *testing.T) {
|
||||||
var info v2.RequestInfo
|
var info v2.RequestInfo
|
||||||
|
|
Loading…
Reference in a new issue