diff --git a/acl/types.go b/acl/types.go index 1cb22174..f1b373a4 100644 --- a/acl/types.go +++ b/acl/types.go @@ -6,36 +6,37 @@ import ( "strings" ) +// BasicACL is Access Control List that defines who can interact with containers and what exactly they can do. type BasicACL uint32 func (a BasicACL) String() string { - return fmt.Sprintf("0x%x", uint32(a)) + return fmt.Sprintf("0x%08x", uint32(a)) } const ( // PublicBasicRule is a basic ACL value for final public-read-write container for which extended ACL CANNOT be set. - PublicBasicRule = 0x1FBFBFFF + PublicBasicRule BasicACL = 0x1FBFBFFF // PrivateBasicRule is a basic ACL value for final private container for which extended ACL CANNOT be set. - PrivateBasicRule = 0x1C8C8CCC + PrivateBasicRule BasicACL = 0x1C8C8CCC // ReadOnlyBasicRule is a basic ACL value for final public-read container for which extended ACL CANNOT be set. - ReadOnlyBasicRule = 0x1FBF8CFF + ReadOnlyBasicRule BasicACL = 0x1FBF8CFF // PublicAppendRule is a basic ACL value for final public-append container for which extended ACL CANNOT be set. - PublicAppendRule = 0x1FBF9FFF + PublicAppendRule BasicACL = 0x1FBF9FFF // EACLPublicBasicRule is a basic ACL value for non-final public-read-write container for which extended ACL CAN be set. - EACLPublicBasicRule = 0x0FBFBFFF + EACLPublicBasicRule BasicACL = 0x0FBFBFFF // EACLPrivateBasicRule is a basic ACL value for non-final private container for which extended ACL CAN be set. - EACLPrivateBasicRule = 0x0C8C8CCC + EACLPrivateBasicRule BasicACL = 0x0C8C8CCC // EACLReadOnlyBasicRule is a basic ACL value for non-final public-read container for which extended ACL CAN be set. - EACLReadOnlyBasicRule = 0x0FBF8CFF + EACLReadOnlyBasicRule BasicACL = 0x0FBF8CFF // EACLPublicAppendRule is a basic ACL value for non-final public-append container for which extended ACL CAN be set. - EACLPublicAppendRule = 0x0FBF9FFF + EACLPublicAppendRule BasicACL = 0x0FBF9FFF ) const ( @@ -65,7 +66,7 @@ const ( ) // ParseBasicACL parse string ACL (well-known names or hex representation). -func ParseBasicACL(basicACL string) (uint32, error) { +func ParseBasicACL(basicACL string) (BasicACL, error) { switch basicACL { case PublicBasicName: return PublicBasicRule, nil @@ -84,13 +85,13 @@ func ParseBasicACL(basicACL string) (uint32, error) { case EACLPublicAppendName: return EACLPublicAppendRule, nil default: - basicACL = strings.Trim(strings.ToLower(basicACL), "0x") + basicACL = strings.TrimPrefix(strings.ToLower(basicACL), "0x") value, err := strconv.ParseUint(basicACL, 16, 32) if err != nil { return 0, fmt.Errorf("can't parse basic ACL: %s", basicACL) } - return uint32(value), nil + return BasicACL(value), nil } } diff --git a/acl/types_test.go b/acl/types_test.go index 8969a22f..9bf0494f 100644 --- a/acl/types_test.go +++ b/acl/types_test.go @@ -9,7 +9,7 @@ import ( func TestParser(t *testing.T) { for _, tc := range []struct { acl string - expected uint32 + expected BasicACL err bool }{ { @@ -78,5 +78,5 @@ func TestString(t *testing.T) { acl2, err := ParseBasicACL(PrivateBasicName) require.NoError(t, err) - require.Equal(t, "0x1c8c8ccc", BasicACL(acl2).String()) + require.Equal(t, "0x1c8c8ccc", acl2.String()) } diff --git a/container/container.go b/container/container.go index 02e5320c..7449ce22 100644 --- a/container/container.go +++ b/container/container.go @@ -5,6 +5,7 @@ import ( "github.com/google/uuid" "github.com/nspcc-dev/neofs-api-go/v2/container" + "github.com/nspcc-dev/neofs-sdk-go/acl" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/owner" @@ -128,8 +129,8 @@ func (c *Container) BasicACL() uint32 { return c.v2.GetBasicACL() } -func (c *Container) SetBasicACL(v uint32) { - c.v2.SetBasicACL(v) +func (c *Container) SetBasicACL(v acl.BasicACL) { + c.v2.SetBasicACL(uint32(v)) } func (c *Container) Attributes() Attributes { diff --git a/container/opts.go b/container/opts.go index d9ac6671..91a84394 100644 --- a/container/opts.go +++ b/container/opts.go @@ -11,7 +11,7 @@ type ( Option func(*containerOptions) containerOptions struct { - acl uint32 + acl acl.BasicACL policy *netmap.PlacementPolicy attributes Attributes owner *owner.ID @@ -43,7 +43,7 @@ func WithReadOnlyBasicACL() Option { } } -func WithCustomBasicACL(acl uint32) Option { +func WithCustomBasicACL(acl acl.BasicACL) Option { return func(option *containerOptions) { option.acl = acl }