bucketpolicy: checkBucketPolicy should keep resources in map.

This is done to make sure to avoid appending duplicates for
resources for each actions.
This commit is contained in:
Harshavardhana 2016-03-22 17:03:11 -07:00
parent 600a932acb
commit 996d2e2a10
1 changed files with 7 additions and 2 deletions

View File

@ -193,7 +193,7 @@ var invalidPrefixActions = map[string]struct{}{
func checkBucketPolicy(bucket string, bucketPolicy BucketPolicy) APIErrorCode { func checkBucketPolicy(bucket string, bucketPolicy BucketPolicy) APIErrorCode {
// Validate statements for special actions and collect resources // Validate statements for special actions and collect resources
// for others to validate nesting. // for others to validate nesting.
var resources []string var resourceMap = make(map[string]struct{})
for _, statement := range bucketPolicy.Statements { for _, statement := range bucketPolicy.Statements {
for _, action := range statement.Actions { for _, action := range statement.Actions {
for _, resource := range statement.Resources { for _, resource := range statement.Resources {
@ -211,12 +211,17 @@ func checkBucketPolicy(bucket string, bucketPolicy BucketPolicy) APIErrorCode {
return ErrMalformedPolicy return ErrMalformedPolicy
} }
// All valid resources collect them separately to verify nesting. // All valid resources collect them separately to verify nesting.
resources = append(resources, resourcePrefix) resourceMap[resourcePrefix] = struct{}{}
} }
} }
} }
} }
var resources []string
for resource := range resourceMap {
resources = append(resources, resource)
}
// Sort strings as shorter first. // Sort strings as shorter first.
sort.Strings(resources) sort.Strings(resources)