From 90f05d444831bbc9f333d811349d2aa07f1c3536 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 30 Dec 2021 12:07:52 +0300 Subject: [PATCH] [#1066] cli: Support basic ACL constants without final flag Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/container.go | 70 ++++++++++++++++++------------ go.mod | 2 +- go.sum | 4 +- 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 8e8b70e15..62e40e925 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -38,8 +38,26 @@ const ( basicACLPrivate = "private" basicACLReadOnly = "public-read" basicACLPublic = "public-read-write" + basicACLAppend = "public-append" + + basicACLNoFinalPrivate = "eacl-private" + basicACLNoFinalReadOnly = "eacl-public-read" + basicACLNoFinalPublic = "eacl-public-read-write" + basicACLNoFinalAppend = "eacl-public-append" ) +var wellKnownBasicACL = map[string]uint32{ + basicACLPublic: acl.PublicBasicRule, + basicACLPrivate: acl.PrivateBasicRule, + basicACLReadOnly: acl.ReadOnlyBasicRule, + basicACLAppend: acl.PublicAppendRule, + + basicACLNoFinalPublic: acl.EACLPublicBasicRule, + basicACLNoFinalPrivate: acl.EACLPrivateBasicRule, + basicACLNoFinalReadOnly: acl.EACLReadOnlyBasicRule, + basicACLNoFinalAppend: acl.EACLPublicAppendRule, +} + const sessionTokenFlag = "session" // path to a file with encoded session token @@ -440,7 +458,7 @@ func initContainerCreateCmd() { flags := createContainerCmd.Flags() - flags.StringVar(&containerACL, "basic-acl", basicACLPrivate, fmt.Sprintf("hex encoded basic ACL value or keywords '%s', '%s', '%s'", basicACLPublic, basicACLPrivate, basicACLReadOnly)) + flags.StringVar(&containerACL, "basic-acl", basicACLPrivate, fmt.Sprintf("hex encoded basic ACL value or keywords like '%s', '%s', '%s'", basicACLPublic, basicACLPrivate, basicACLNoFinalReadOnly)) flags.StringVarP(&containerPolicy, "policy", "p", "", "QL-encoded or JSON-encoded placement policy or path to file with it") flags.StringSliceVarP(&containerAttributes, "attributes", "a", nil, "comma separated pairs of container attributes in form of Key1=Value1,Key2=Value2") flags.StringVarP(&containerNonce, "nonce", "n", "", "UUIDv4 nonce value for container") @@ -651,23 +669,18 @@ func parseAttributes(attributes []string) ([]*container.Attribute, error) { } func parseBasicACL(basicACL string) (uint32, error) { - switch basicACL { - case basicACLPublic: - return acl.PublicBasicRule, nil - case basicACLPrivate: - return acl.PrivateBasicRule, nil - case basicACLReadOnly: - return acl.ReadOnlyBasicRule, nil - default: - basicACL = strings.Trim(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 + if value, ok := wellKnownBasicACL[basicACL]; ok { + return value, nil } + + basicACL = strings.Trim(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 } func parseNonce(nonce string) (uuid.UUID, error) { @@ -731,17 +744,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco cmd.Println("owner ID:", cnr.OwnerID()) basicACL := cnr.BasicACL() - cmd.Printf("basic ACL: %s", strconv.FormatUint(uint64(basicACL), 16)) - switch basicACL { - case acl.PublicBasicRule: - cmd.Printf(" (%s)\n", basicACLPublic) - case acl.PrivateBasicRule: - cmd.Printf(" (%s)\n", basicACLPrivate) - case acl.ReadOnlyBasicRule: - cmd.Printf(" (%s)\n", basicACLReadOnly) - default: - cmd.Println() - } + prettyPrintBasicACL(cmd, basicACL) for _, attribute := range cnr.Attributes() { if attribute.Key() == container.AttributeTimestamp { @@ -821,3 +824,14 @@ func printJSONMarshaler(cmd *cobra.Command, j json.Marshaler, entity string) { } cmd.Println(buf) } + +func prettyPrintBasicACL(cmd *cobra.Command, basicACL uint32) { + cmd.Printf("basic ACL: %.8x", basicACL) + for k, v := range wellKnownBasicACL { + if v == basicACL { + cmd.Printf(" (%s)\n", k) + return + } + } + cmd.Println() +} diff --git a/go.mod b/go.mod index 604139095..d07b44bc0 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/neo-go v0.98.0 github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 - github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211228125935-3edaf9ecb644 + github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80 github.com/nspcc-dev/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index 3fb24a141..91b8f1d15 100644 --- a/go.sum +++ b/go.sum @@ -371,8 +371,8 @@ github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BE github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211228125935-3edaf9ecb644 h1:AytMrbwumNIfjYcG1ng+OuEXTtBslya96UAYj/h+dTQ= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211228125935-3edaf9ecb644/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80 h1:qM011x26c1Q74peWNpXHuE0IqbEwDF0ksqAwbh9xZn8= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211230072947-1fe37df88f80/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=