forked from TrueCloudLab/frostfs-node
[#1066] cli: Support basic ACL constants without final flag
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
56b8793520
commit
90f05d4448
3 changed files with 45 additions and 31 deletions
|
@ -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,14 +669,10 @@ 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:
|
||||
if value, ok := wellKnownBasicACL[basicACL]; ok {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
basicACL = strings.Trim(strings.ToLower(basicACL), "0x")
|
||||
|
||||
value, err := strconv.ParseUint(basicACL, 16, 32)
|
||||
|
@ -668,7 +682,6 @@ func parseBasicACL(basicACL string) (uint32, error) {
|
|||
|
||||
return uint32(value), nil
|
||||
}
|
||||
}
|
||||
|
||||
func parseNonce(nonce string) (uuid.UUID, error) {
|
||||
if nonce == "" {
|
||||
|
@ -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()
|
||||
}
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
Loading…
Reference in a new issue