diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2022-07-11 01:49:25 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-11 01:49:25 -0700 |
| commit | 7929a50327afe495c1913d198958fb0b27d7bd67 (patch) | |
| tree | 16c6b98d5b20e314f6b5e33a14bedcc854abccd3 | |
| parent | 37578929d4f74ec9c8b610df691918b79cee79ca (diff) | |
| parent | 7dbf19d09a137fb1b792459e2b6fb75e49fa8a3e (diff) | |
| download | seaweedfs-7929a50327afe495c1913d198958fb0b27d7bd67.tar.xz seaweedfs-7929a50327afe495c1913d198958fb0b27d7bd67.zip | |
Merge pull request #3296 from guo-sj/fix_put_user_policy
refine PutUserPolicy
| -rw-r--r-- | weed/iamapi/iamapi_management_handlers.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/weed/iamapi/iamapi_management_handlers.go b/weed/iamapi/iamapi_management_handlers.go index 994224688..d3b1e7b28 100644 --- a/weed/iamapi/iamapi_management_handlers.go +++ b/weed/iamapi/iamapi_management_handlers.go @@ -204,6 +204,7 @@ func (iama *IamApiServer) CreatePolicy(s3cfg *iam_pb.S3ApiConfiguration, values return resp, nil } +// https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutUserPolicy.html func (iama *IamApiServer) PutUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values url.Values) (resp PutUserPolicyResponse, err error) { userName := values.Get("UserName") policyName := values.Get("PolicyName") @@ -212,15 +213,21 @@ func (iama *IamApiServer) PutUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values if err != nil { return PutUserPolicyResponse{}, err } + isFound := false policyDocuments[policyName] = &policyDocument actions := GetActions(&policyDocument) for _, ident := range s3cfg.Identities { - if userName == ident.Name { - for _, action := range actions { - ident.Actions = append(ident.Actions, action) - } - break + if userName != ident.Name { + continue + } + isFound = true + for _, action := range actions { + ident.Actions = append(ident.Actions, action) } + break + } + if !isFound { + return resp, fmt.Errorf("%s: the user with name %s cannot be found", iam.ErrCodeNoSuchEntityException, userName) } return resp, nil } |
