2020-08-25 11:52:18 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl"
|
2020-09-15 08:03:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
2020-08-31 08:15:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2020-08-25 11:52:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
NewOption interface {
|
|
|
|
apply(*containerOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
containerOptions struct {
|
|
|
|
acl uint32
|
2020-09-15 08:03:15 +00:00
|
|
|
policy *netmap.PlacementPolicy
|
2020-11-11 13:49:54 +00:00
|
|
|
attributes Attributes
|
2020-08-31 08:15:46 +00:00
|
|
|
owner *owner.ID
|
2020-08-25 11:52:18 +00:00
|
|
|
nonce uuid.UUID
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func defaultContainerOptions() containerOptions {
|
|
|
|
rand, err := uuid.NewRandom()
|
|
|
|
if err != nil {
|
|
|
|
panic("can't create new random " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return containerOptions{
|
2021-06-08 13:32:29 +00:00
|
|
|
acl: acl.PrivateBasicRule,
|
|
|
|
nonce: rand,
|
2020-08-25 11:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type funcContainerOption struct {
|
|
|
|
f func(*containerOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fco *funcContainerOption) apply(co *containerOptions) {
|
|
|
|
fco.f(co)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFuncContainerOption(f func(option *containerOptions)) *funcContainerOption {
|
|
|
|
return &funcContainerOption{
|
|
|
|
f: f,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithPublicBasicACL() NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
option.acl = acl.PublicBasicRule
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithReadOnlyBasicACL() NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
option.acl = acl.ReadOnlyBasicRule
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithCustomBasicACL(acl uint32) NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
option.acl = acl
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithNonce(nonce uuid.UUID) NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
option.nonce = nonce
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-31 08:15:46 +00:00
|
|
|
func WithOwnerID(id *owner.ID) NewOption {
|
2020-08-25 11:52:18 +00:00
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
2020-08-31 08:15:46 +00:00
|
|
|
option.owner = id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithNEO3Wallet(w *owner.NEO3Wallet) NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
if option.owner == nil {
|
|
|
|
option.owner = new(owner.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
option.owner.SetNeo3Wallet(w)
|
2020-08-25 11:52:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-15 08:03:15 +00:00
|
|
|
func WithPolicy(policy *netmap.PlacementPolicy) NewOption {
|
2020-08-25 11:52:18 +00:00
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
|
|
|
option.policy = policy
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAttribute(key, value string) NewOption {
|
|
|
|
return newFuncContainerOption(func(option *containerOptions) {
|
2020-11-11 13:49:54 +00:00
|
|
|
attr := NewAttribute()
|
|
|
|
attr.SetKey(key)
|
|
|
|
attr.SetValue(value)
|
|
|
|
|
2020-08-25 11:52:18 +00:00
|
|
|
option.attributes = append(option.attributes, attr)
|
|
|
|
})
|
|
|
|
}
|