MCPcopy
hub / github.com/minio/minio-go / GetPolicies

Function GetPolicies

pkg/policy/bucket-policy.go:609–637  ·  view source on GitHub ↗

GetPolicies - returns a map of policies of given bucket name, prefix in given statements.

(statements []Statement, bucketName, prefix string)

Source from the content-addressed store, hash-verified

607
608// GetPolicies - returns a map of policies of given bucket name, prefix in given statements.
609func GetPolicies(statements []Statement, bucketName, prefix string) map[string]BucketPolicy {
610 policyRules := map[string]BucketPolicy{}
611 objResources := set.NewStringSet()
612 // Search all resources related to objects policy
613 for _, s := range statements {
614 for r := range s.Resources {
615 if strings.HasPrefix(r, awsResourcePrefix+bucketName+"/"+prefix) {
616 objResources.Add(r)
617 }
618 }
619 }
620
621 // Pretend that policy resource as an actual object and fetch its policy
622 for r := range objResources {
623 // Put trailing * if exists in asterisk
624 asterisk := ""
625 if strings.HasSuffix(r, "*") {
626 r = r[:len(r)-1]
627 asterisk = "*"
628 }
629 var objectPath string
630 if len(r) >= len(awsResourcePrefix+bucketName)+1 {
631 objectPath = r[len(awsResourcePrefix+bucketName)+1:]
632 }
633 p := GetPolicy(statements, bucketName, objectPath)
634 policyRules[bucketName+"/"+objectPath+asterisk] = p
635 }
636 return policyRules
637}
638
639// SetPolicy - Returns new statements containing policy of given bucket name and prefix are appended.
640func SetPolicy(statements []Statement, policy BucketPolicy, bucketName, prefix string) []Statement {

Callers 1

TestListBucketPoliciesFunction · 0.85

Calls 3

AddMethod · 0.95
NewStringSetFunction · 0.92
GetPolicyFunction · 0.85

Tested by 1

TestListBucketPoliciesFunction · 0.68