Browse Source

Merge pull request #3296 from guo-sj/fix_put_user_policy

refine PutUserPolicy
pull/3299/head
Chris Lu 2 years ago
committed by GitHub
parent
commit
7929a50327
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      weed/iamapi/iamapi_management_handlers.go

9
weed/iamapi/iamapi_management_handlers.go

@ -204,6 +204,7 @@ func (iama *IamApiServer) CreatePolicy(s3cfg *iam_pb.S3ApiConfiguration, values
return resp, nil 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) { func (iama *IamApiServer) PutUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values url.Values) (resp PutUserPolicyResponse, err error) {
userName := values.Get("UserName") userName := values.Get("UserName")
policyName := values.Get("PolicyName") policyName := values.Get("PolicyName")
@ -212,15 +213,21 @@ func (iama *IamApiServer) PutUserPolicy(s3cfg *iam_pb.S3ApiConfiguration, values
if err != nil { if err != nil {
return PutUserPolicyResponse{}, err return PutUserPolicyResponse{}, err
} }
isFound := false
policyDocuments[policyName] = &policyDocument policyDocuments[policyName] = &policyDocument
actions := GetActions(&policyDocument) actions := GetActions(&policyDocument)
for _, ident := range s3cfg.Identities { for _, ident := range s3cfg.Identities {
if userName == ident.Name {
if userName != ident.Name {
continue
}
isFound = true
for _, action := range actions { for _, action := range actions {
ident.Actions = append(ident.Actions, action) ident.Actions = append(ident.Actions, action)
} }
break break
} }
if !isFound {
return resp, fmt.Errorf("%s: the user with name %s cannot be found", iam.ErrCodeNoSuchEntityException, userName)
} }
return resp, nil return resp, nil
} }

Loading…
Cancel
Save