forked from TrueCloudLab/frostfs-node
[#69] object/acl: Construct service from options
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
e5898c9ca8
commit
30e6912c7b
3 changed files with 74 additions and 28 deletions
|
@ -292,25 +292,31 @@ func initObjectService(c *cfg) {
|
||||||
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
|
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
|
||||||
objectTransportGRPC.New(
|
objectTransportGRPC.New(
|
||||||
acl.New(
|
acl.New(
|
||||||
acl.NewSenderClassifier(
|
acl.WithSenderClassifier(
|
||||||
c.cfgNetmap.wrapper,
|
acl.NewSenderClassifier(
|
||||||
c.cfgNetmap.wrapper,
|
c.cfgNetmap.wrapper,
|
||||||
|
c.cfgNetmap.wrapper,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
c.cfgObject.cnrStorage,
|
acl.WithContainerSource(
|
||||||
objectService.NewSignService(
|
c.cfgObject.cnrStorage,
|
||||||
c.key,
|
),
|
||||||
objectService.NewTransportSplitter(
|
acl.WithNextService(
|
||||||
c.cfgGRPC.maxChunkSize,
|
objectService.NewSignService(
|
||||||
c.cfgGRPC.maxAddrAmount,
|
c.key,
|
||||||
&objectSvc{
|
objectService.NewTransportSplitter(
|
||||||
put: sPutV2,
|
c.cfgGRPC.maxChunkSize,
|
||||||
search: sSearchV2,
|
c.cfgGRPC.maxAddrAmount,
|
||||||
head: sHeadV2,
|
&objectSvc{
|
||||||
rng: sRangeV2,
|
put: sPutV2,
|
||||||
get: sGetV2,
|
search: sSearchV2,
|
||||||
rngHash: sRangeHashV2,
|
head: sHeadV2,
|
||||||
delete: sDeleteV2,
|
rng: sRangeV2,
|
||||||
},
|
get: sGetV2,
|
||||||
|
rngHash: sRangeHashV2,
|
||||||
|
delete: sDeleteV2,
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -16,9 +16,7 @@ import (
|
||||||
type (
|
type (
|
||||||
// Service checks basic ACL rules.
|
// Service checks basic ACL rules.
|
||||||
Service struct {
|
Service struct {
|
||||||
containers core.Source
|
*cfg
|
||||||
sender SenderClassifier
|
|
||||||
next object.Service
|
|
||||||
}
|
}
|
||||||
|
|
||||||
putStreamBasicChecker struct {
|
putStreamBasicChecker struct {
|
||||||
|
@ -47,6 +45,17 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Option represents Service constructor option.
|
||||||
|
type Option func(*cfg)
|
||||||
|
|
||||||
|
type cfg struct {
|
||||||
|
containers core.Source
|
||||||
|
|
||||||
|
sender SenderClassifier
|
||||||
|
|
||||||
|
next object.Service
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrMalformedRequest = errors.New("malformed request")
|
ErrMalformedRequest = errors.New("malformed request")
|
||||||
ErrUnknownRole = errors.New("can't classify request sender")
|
ErrUnknownRole = errors.New("can't classify request sender")
|
||||||
|
@ -54,16 +63,20 @@ var (
|
||||||
ErrBasicAccessDenied = errors.New("access denied by basic acl")
|
ErrBasicAccessDenied = errors.New("access denied by basic acl")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func defaultCfg() *cfg {
|
||||||
|
return new(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
// New is a constructor for object ACL checking service.
|
// New is a constructor for object ACL checking service.
|
||||||
func New(
|
func New(opts ...Option) Service {
|
||||||
c SenderClassifier,
|
cfg := defaultCfg()
|
||||||
cnr core.Source,
|
|
||||||
next object.Service) Service {
|
for i := range opts {
|
||||||
|
opts[i](cfg)
|
||||||
|
}
|
||||||
|
|
||||||
return Service{
|
return Service{
|
||||||
containers: cnr,
|
cfg: cfg,
|
||||||
sender: c,
|
|
||||||
next: next,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
pkg/services/object/acl/opts.go
Normal file
27
pkg/services/object/acl/opts.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package acl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithContainerSource returns option to set container source.
|
||||||
|
func WithContainerSource(v container.Source) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.containers = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSenderClassifier returns option to set sender classifier.
|
||||||
|
func WithSenderClassifier(v SenderClassifier) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.sender = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithNextService returns option to set next object service.
|
||||||
|
func WithNextService(v object.Service) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.next = v
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue