From ad5e8f68ec04c37d16b3c86834e1ecc524c2680b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=98=8C=E6=9E=97?= Date: Wed, 13 Jul 2022 11:36:11 +0800 Subject: [PATCH 1/2] Check whether there is a duplicate accessKey when modifying iam --- weed/shell/command_s3_configure.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/weed/shell/command_s3_configure.go b/weed/shell/command_s3_configure.go index ddcafd847..c3c0a0d34 100644 --- a/weed/shell/command_s3_configure.go +++ b/weed/shell/command_s3_configure.go @@ -2,6 +2,7 @@ package shell import ( "bytes" + "errors" "flag" "fmt" "github.com/chrislusf/seaweedfs/weed/filer" @@ -164,6 +165,17 @@ func (c *commandS3Configure) Do(args []string, commandEnv *CommandEnv, writer io s3cfg.Identities = append(s3cfg.Identities, &identity) } + accessKeySet := make(map[string]string) + for _, ident := range s3cfg.Identities { + for _, cred := range ident.Credentials { + if userName, found := accessKeySet[cred.AccessKey]; !found { + accessKeySet[cred.AccessKey] = ident.Name + } else { + return errors.New(fmt.Sprintf("duplicate accessKey: %s, already configured in user[%s]", cred.AccessKey, userName)) + } + } + } + buf.Reset() filer.ProtoToText(&buf, s3cfg) From 392da4e0385ac8bcce5ac0d286277a71651af225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=98=8C=E6=9E=97?= Date: Wed, 13 Jul 2022 11:39:45 +0800 Subject: [PATCH 2/2] Make the prompt information clearer --- weed/shell/command_s3_configure.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/shell/command_s3_configure.go b/weed/shell/command_s3_configure.go index c3c0a0d34..0660b7889 100644 --- a/weed/shell/command_s3_configure.go +++ b/weed/shell/command_s3_configure.go @@ -171,7 +171,7 @@ func (c *commandS3Configure) Do(args []string, commandEnv *CommandEnv, writer io if userName, found := accessKeySet[cred.AccessKey]; !found { accessKeySet[cred.AccessKey] = ident.Name } else { - return errors.New(fmt.Sprintf("duplicate accessKey: %s, already configured in user[%s]", cred.AccessKey, userName)) + return errors.New(fmt.Sprintf("duplicate accessKey[%s], already configured in user[%s]", cred.AccessKey, userName)) } } }