2021-11-08 12:25:13 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2022-01-13 13:16:35 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/acl"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2021-11-08 12:25:13 +00:00
|
|
|
Option func(*containerOptions)
|
2021-11-08 12:25:13 +00:00
|
|
|
|
|
|
|
containerOptions struct {
|
2021-12-29 12:36:01 +00:00
|
|
|
acl acl.BasicACL
|
2021-11-08 12:25:13 +00:00
|
|
|
policy *netmap.PlacementPolicy
|
|
|
|
attributes Attributes
|
|
|
|
owner *owner.ID
|
|
|
|
nonce uuid.UUID
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func defaultContainerOptions() containerOptions {
|
|
|
|
rand, err := uuid.NewRandom()
|
|
|
|
if err != nil {
|
|
|
|
panic("can't create new random " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return containerOptions{
|
|
|
|
acl: acl.PrivateBasicRule,
|
|
|
|
nonce: rand,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithPublicBasicACL() Option {
|
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.acl = acl.PublicBasicRule
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithReadOnlyBasicACL() Option {
|
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.acl = acl.ReadOnlyBasicRule
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 12:36:01 +00:00
|
|
|
func WithCustomBasicACL(acl acl.BasicACL) Option {
|
2021-11-08 12:25:13 +00:00
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.acl = acl
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithNonce(nonce uuid.UUID) Option {
|
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.nonce = nonce
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithOwnerID(id *owner.ID) Option {
|
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.owner = id
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 13:16:35 +00:00
|
|
|
func WithOwnerPublicKey(pub *ecdsa.PublicKey) Option {
|
2021-11-08 12:25:13 +00:00
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
if option.owner == nil {
|
|
|
|
option.owner = new(owner.ID)
|
|
|
|
}
|
|
|
|
|
2022-01-13 13:16:35 +00:00
|
|
|
option.owner.SetPublicKey(pub)
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithPolicy(policy *netmap.PlacementPolicy) Option {
|
|
|
|
return func(option *containerOptions) {
|
2021-11-08 12:25:13 +00:00
|
|
|
option.policy = policy
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 12:25:13 +00:00
|
|
|
func WithAttribute(key, value string) Option {
|
|
|
|
return func(option *containerOptions) {
|
2022-03-11 09:13:56 +00:00
|
|
|
index := len(option.attributes)
|
|
|
|
option.attributes = append(option.attributes, Attribute{})
|
|
|
|
option.attributes[index].SetKey(key)
|
|
|
|
option.attributes[index].SetValue(value)
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|
2021-11-08 12:25:13 +00:00
|
|
|
}
|