[#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 43 additions and 29 deletions
|
@ -38,8 +38,26 @@ const (
|
||||||
basicACLPrivate = "private"
|
basicACLPrivate = "private"
|
||||||
basicACLReadOnly = "public-read"
|
basicACLReadOnly = "public-read"
|
||||||
basicACLPublic = "public-read-write"
|
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"
|
const sessionTokenFlag = "session"
|
||||||
|
|
||||||
// path to a file with encoded session token
|
// path to a file with encoded session token
|
||||||
|
@ -440,7 +458,7 @@ func initContainerCreateCmd() {
|
||||||
|
|
||||||
flags := createContainerCmd.Flags()
|
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.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.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")
|
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) {
|
func parseBasicACL(basicACL string) (uint32, error) {
|
||||||
switch basicACL {
|
if value, ok := wellKnownBasicACL[basicACL]; ok {
|
||||||
case basicACLPublic:
|
return value, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
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())
|
cmd.Println("owner ID:", cnr.OwnerID())
|
||||||
|
|
||||||
basicACL := cnr.BasicACL()
|
basicACL := cnr.BasicACL()
|
||||||
cmd.Printf("basic ACL: %s", strconv.FormatUint(uint64(basicACL), 16))
|
prettyPrintBasicACL(cmd, basicACL)
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, attribute := range cnr.Attributes() {
|
for _, attribute := range cnr.Attributes() {
|
||||||
if attribute.Key() == container.AttributeTimestamp {
|
if attribute.Key() == container.AttributeTimestamp {
|
||||||
|
@ -821,3 +824,14 @@ func printJSONMarshaler(cmd *cobra.Command, j json.Marshaler, entity string) {
|
||||||
}
|
}
|
||||||
cmd.Println(buf)
|
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/hrw v1.0.9
|
||||||
github.com/nspcc-dev/neo-go v0.98.0
|
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-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/nspcc-dev/tzhash v1.4.0
|
||||||
github.com/panjf2000/ants/v2 v2.4.0
|
github.com/panjf2000/ants/v2 v2.4.0
|
||||||
github.com/paulmach/orb v0.2.2
|
github.com/paulmach/orb v0.2.2
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
Loading…
Reference in a new issue