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
+34
View File
@@ -582,6 +582,40 @@ func (web *webAPIHandlers) GetBucketPolicy(r *http.Request, args *GetBucketPolic
return nil
}
// GetAllBucketPolicyArgs - get all bucket policy args.
type GetAllBucketPolicyArgs struct {
BucketName string `json:"bucketName"`
}
// GetAllBucketPolicyRep - get all bucket policy reply.
type GetAllBucketPolicyRep struct {
UIVersion string `json:"uiVersion"`
Policies map[string]policy.BucketPolicy `json:"policies"`
}
// GetAllBucketPolicy - get all bucket policy.
func (web *webAPIHandlers) GetAllBucketPolicy(r *http.Request, args *GetAllBucketPolicyArgs, reply *GetAllBucketPolicyRep) error {
if !isJWTReqAuthenticated(r) {
return &json2.Error{Message: "Unauthorized request"}
}
objectAPI := web.ObjectAPI()
if objectAPI == nil {
return &json2.Error{Message: "Server not initialized"}
}
policyInfo, err := readBucketAccessPolicy(objectAPI, args.BucketName)
if err != nil {
return &json2.Error{Message: err.Error()}
}
policies := policy.GetPolicies(policyInfo.Statements, args.BucketName)
reply.UIVersion = miniobrowser.UIVersion
reply.Policies = policies
return nil
}
// SetBucketPolicyArgs - set bucket policy args.
type SetBucketPolicyArgs struct {
BucketName string `json:"bucketName"`