forked from TrueCloudLab/frostfs-node
[#1533] acl: Upgrade NeoFS SDK Go with refactored basic ACL
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b13dca8052
commit
305dd7598f
15 changed files with 115 additions and 429 deletions
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/acl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
||||
|
@ -23,31 +23,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// keywords of predefined basic ACL values
|
||||
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]acl.BasicACL{
|
||||
basicACLPublic: acl.PublicBasicRule,
|
||||
basicACLPrivate: acl.PrivateBasicRule,
|
||||
basicACLReadOnly: acl.ReadOnlyBasicRule,
|
||||
basicACLAppend: acl.PublicAppendRule,
|
||||
|
||||
basicACLNoFinalPublic: acl.EACLPublicBasicRule,
|
||||
basicACLNoFinalPrivate: acl.EACLPrivateBasicRule,
|
||||
basicACLNoFinalReadOnly: acl.EACLReadOnlyBasicRule,
|
||||
basicACLNoFinalAppend: acl.EACLPublicAppendRule,
|
||||
}
|
||||
|
||||
var (
|
||||
containerACL string
|
||||
containerNonce string
|
||||
|
@ -80,8 +55,8 @@ It will be stored in sidechain when inner ring will accepts it.`,
|
|||
attributes, err := parseAttributes(containerAttributes)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
||||
basicACL, err := parseBasicACL(containerACL)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
var basicACL acl.Basic
|
||||
common.ExitOnErr(cmd, "decode basic ACL string: %w", basicACL.DecodeString(containerACL))
|
||||
|
||||
nonce, err := parseNonce(containerNonce)
|
||||
common.ExitOnErr(cmd, "", err)
|
||||
|
@ -157,7 +132,9 @@ func initContainerCreateCmd() {
|
|||
|
||||
flags := createContainerCmd.Flags()
|
||||
|
||||
flags.StringVar(&containerACL, "basic-acl", basicACLPrivate, fmt.Sprintf("hex encoded basic ACL value or keywords like '%s', '%s', '%s'", basicACLPublic, basicACLPrivate, basicACLNoFinalReadOnly))
|
||||
flags.StringVar(&containerACL, "basic-acl", acl.NamePrivate, fmt.Sprintf("hex encoded basic ACL value or keywords like '%s', '%s', '%s'",
|
||||
acl.NamePublicRW, acl.NamePrivate, acl.NamePublicROExtended,
|
||||
))
|
||||
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")
|
||||
|
@ -226,21 +203,6 @@ func parseAttributes(attributes []string) ([]container.Attribute, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func parseBasicACL(basicACL string) (acl.BasicACL, error) {
|
||||
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 acl.BasicACL(value), nil
|
||||
}
|
||||
|
||||
func parseNonce(nonce string) (uuid.UUID, error) {
|
||||
if nonce == "" {
|
||||
result := uuid.New()
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
|
||||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/acl"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -120,7 +120,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco
|
|||
cmd.Println("owner ID:", cnr.OwnerID())
|
||||
|
||||
basicACL := cnr.BasicACL()
|
||||
prettyPrintBasicACL(cmd, acl.BasicACL(basicACL))
|
||||
prettyPrintBasicACL(cmd, basicACL)
|
||||
|
||||
for _, attribute := range cnr.Attributes() {
|
||||
if attribute.Key() == container.AttributeTimestamp {
|
||||
|
@ -152,13 +152,33 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco
|
|||
}
|
||||
}
|
||||
|
||||
func prettyPrintBasicACL(cmd *cobra.Command, basicACL acl.BasicACL) {
|
||||
cmd.Printf("basic ACL: %s", basicACL)
|
||||
for k, v := range wellKnownBasicACL {
|
||||
if v == basicACL {
|
||||
cmd.Printf(" (%s)\n", k)
|
||||
return
|
||||
}
|
||||
func prettyPrintBasicACL(cmd *cobra.Command, basicACL acl.Basic) {
|
||||
cmd.Printf("basic ACL: %s", basicACL.EncodeToString())
|
||||
|
||||
var prettyName string
|
||||
|
||||
switch basicACL {
|
||||
case acl.Private:
|
||||
prettyName = acl.NamePrivate
|
||||
case acl.PrivateExtended:
|
||||
prettyName = acl.NamePrivateExtended
|
||||
case acl.PublicRO:
|
||||
prettyName = acl.NamePublicRO
|
||||
case acl.PublicROExtended:
|
||||
prettyName = acl.NamePublicROExtended
|
||||
case acl.PublicRW:
|
||||
prettyName = acl.NamePublicRW
|
||||
case acl.PublicRWExtended:
|
||||
prettyName = acl.NamePublicRWExtended
|
||||
case acl.PublicAppend:
|
||||
prettyName = acl.NamePublicAppend
|
||||
case acl.PublicAppendExtended:
|
||||
prettyName = acl.NamePublicAppendExtended
|
||||
}
|
||||
|
||||
if prettyName != "" {
|
||||
cmd.Printf(" (%s)", prettyName)
|
||||
}
|
||||
|
||||
cmd.Println()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue