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 | Bin 93049 -> 93049 bytes 3 files changed, 43 insertions(+), 29 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 3fb24a14115fcb688ed3a43b0c4b2fd5bf87127f..91b8f1d157caba9d181c2cd900e35465a470db5e 100644 GIT binary patch delta 113 zcmex)jrHd>)(t9sF2)81=0=t#=DLPysmA6hX%-e~76u9#hE|2X28M)(t9sE=CrHMy8g=rn<(dDT!&8smV!ZCMF6QhE|T1CB8*T<)yiPo@rT; z$?k@E>DvCKt`Q+6PQ^KuiI!%ej*(gV8QLi!fs-e;iBGQYlM=;h*yeS8r|$p&#`PzP