web: add method to get all policies for given bucket name. (#2756)

Refer #1858
This commit is contained in:
Bala FA
2016-09-22 23:06:45 -07:00
committed by Harshavardhana
parent e375d822da
commit aa579bbc20
4 changed files with 131 additions and 3 deletions

View File

@@ -563,6 +563,33 @@ func GetPolicy(statements []Statement, bucketName string, prefix string) BucketP
return policy
}
// GetPolicies returns a map of policies rules of given bucket name, prefix in given statements.
func GetPolicies(statements []Statement, bucketName string) map[string]BucketPolicy {
policyRules := map[string]BucketPolicy{}
objResources := set.NewStringSet()
// Search all resources related to objects policy
for _, s := range statements {
for r := range s.Resources {
if strings.HasPrefix(r, awsResourcePrefix+bucketName+"/") {
objResources.Add(r)
}
}
}
// Pretend that policy resource as an actual object and fetch its policy
for r := range objResources {
// Put trailing * if exists in asterisk
asterisk := ""
if strings.HasSuffix(r, "*") {
r = r[:len(r)-1]
asterisk = "*"
}
objectPath := r[len(awsResourcePrefix+bucketName)+1 : len(r)]
p := GetPolicy(statements, bucketName, objectPath)
policyRules[bucketName+"/"+objectPath+asterisk] = p
}
return policyRules
}
// Returns new statements containing policy of given bucket name and
// prefix are appended.
func SetPolicy(statements []Statement, policy BucketPolicy, bucketName string, prefix string) []Statement {

6
vendor/vendor.json vendored
View File

@@ -114,10 +114,10 @@
"revisionTime": "2016-02-29T08:42:30-08:00"
},
{
"checksumSHA1": "0OZaeJPgMlA2Txn+1yeAIwEpJvM=",
"checksumSHA1": "qTxOBp3GVxCC70ykb7Hxg6UgWwA=",
"path": "github.com/minio/minio-go/pkg/policy",
"revision": "a2e27c84cd20b86cd781b76639781d6366235d0c",
"revisionTime": "2016-08-23T00:31:21Z"
"revision": "40505f5d08c721dfe5a6450fbdef3bcd6567aa97",
"revisionTime": "2016-09-04T08:12:15Z"
},
{
"checksumSHA1": "A8QOw1aWwc+RtjGozY0XeS5varo=",