From 96a24b5721459e9a377fc5e30814fa330f6f5a74 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 12 Jul 2022 13:40:15 +0300 Subject: [PATCH] [#1490] cli: Require SG members to be unique Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/storagegroup/put.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/neofs-cli/modules/storagegroup/put.go b/cmd/neofs-cli/modules/storagegroup/put.go index 4dce711f5..d8398e5aa 100644 --- a/cmd/neofs-cli/modules/storagegroup/put.go +++ b/cmd/neofs-cli/modules/storagegroup/put.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/ecdsa" "errors" + "fmt" "strconv" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client" @@ -16,7 +17,6 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" @@ -61,11 +61,18 @@ func putSG(cmd *cobra.Command, _ []string) { lifetime, err := strconv.ParseUint(lifetimeStr, 10, 64) common.ExitOnErr(cmd, "could not parse lifetime: %w", err) - members := make([]oidSDK.ID, len(sgMembers)) + members := make([]oid.ID, len(sgMembers)) + uniqueFilter := make(map[oid.ID]struct{}, len(sgMembers)) for i := range sgMembers { - err := members[i].DecodeString(sgMembers[i]) + err = members[i].DecodeString(sgMembers[i]) common.ExitOnErr(cmd, "could not parse object ID: %w", err) + + if _, alreadyExists := uniqueFilter[members[i]]; alreadyExists { + common.ExitOnErr(cmd, "", fmt.Errorf("%s member in not unique", members[i])) + } + + uniqueFilter[members[i]] = struct{}{} } var (