diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go index 65297e473..69ea3ee15 100644 --- a/cmd/web-handlers.go +++ b/cmd/web-handlers.go @@ -575,27 +575,31 @@ func (web *webAPIHandlers) GetBucketPolicy(r *http.Request, args *GetBucketPolic return &json2.Error{Message: err.Error()} } - bucketPolicy := policy.GetPolicy(policyInfo.Statements, args.BucketName, args.Prefix) - reply.UIVersion = miniobrowser.UIVersion - reply.Policy = bucketPolicy + reply.Policy = policy.GetPolicy(policyInfo.Statements, args.BucketName, args.Prefix) return nil } -// GetAllBucketPolicyArgs - get all bucket policy args. -type GetAllBucketPolicyArgs struct { +// ListAllBucketPoliciesArgs - get all bucket policies. +type ListAllBucketPoliciesArgs 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"` +// Collection of canned bucket policy at a given prefix. +type bucketAccessPolicy struct { + Prefix string `json:"prefix"` + Policy policy.BucketPolicy `json:"policy"` +} + +// ListAllBucketPoliciesRep - get all bucket policy reply. +type ListAllBucketPoliciesRep struct { + UIVersion string `json:"uiVersion"` + Policies []bucketAccessPolicy `json:"policies"` } -// GetAllBucketPolicy - get all bucket policy. -func (web *webAPIHandlers) GetAllBucketPolicy(r *http.Request, args *GetAllBucketPolicyArgs, reply *GetAllBucketPolicyRep) error { +// GetllBucketPolicy - get all bucket policy. +func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllBucketPoliciesArgs, reply *ListAllBucketPoliciesRep) error { if !isJWTReqAuthenticated(r) { return &json2.Error{Message: "Unauthorized request"} } @@ -609,11 +613,13 @@ func (web *webAPIHandlers) GetAllBucketPolicy(r *http.Request, args *GetAllBucke return &json2.Error{Message: err.Error()} } - policies := policy.GetPolicies(policyInfo.Statements, args.BucketName) - reply.UIVersion = miniobrowser.UIVersion - reply.Policies = policies - + for prefix, policy := range policy.GetPolicies(policyInfo.Statements, args.BucketName) { + reply.Policies = append(reply.Policies, bucketAccessPolicy{ + Prefix: prefix, + Policy: policy, + }) + } return nil } diff --git a/cmd/web-handlers_test.go b/cmd/web-handlers_test.go index f2f632fd9..89b9b7cd5 100644 --- a/cmd/web-handlers_test.go +++ b/cmd/web-handlers_test.go @@ -868,13 +868,13 @@ func testWebGetBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestE } } -// Wrapper for calling GetAllBucketPolicy Handler -func TestWebHandlerGetAllBucketPolicyHandler(t *testing.T) { - ExecObjectLayerTest(t, testWebGetAllBucketPolicyHandler) +// Wrapper for calling ListAllBucketPolicies Handler +func TestWebHandlerListAllBucketPoliciesHandler(t *testing.T) { + ExecObjectLayerTest(t, testWebListAllBucketPoliciesHandler) } -// testWebGetAllBucketPolicyHandler - Test GetAllBucketPolicy web handler -func testWebGetAllBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestErrHandler) { +// testWebListAllBucketPoliciesHandler - Test ListAllBucketPolicies web handler +func testWebListAllBucketPoliciesHandler(obj ObjectLayer, instanceType string, t TestErrHandler) { // Register the API end points with XL/FS object layer. apiRouter := initTestWebRPCEndPoint(obj) // initialize the server and obtain the credentials and root. @@ -905,19 +905,21 @@ func testWebGetAllBucketPolicyHandler(obj ObjectLayer, instanceType string, t Te t.Fatal("Unexpected error: ", err) } - testCaseResult1 := make(map[string]policy.BucketPolicy) - testCaseResult1[bucketName+"/hello*"] = policy.BucketPolicyReadWrite + testCaseResult1 := []bucketAccessPolicy{{ + Prefix: bucketName + "/hello*", + Policy: policy.BucketPolicyReadWrite, + }} testCases := []struct { bucketName string - expectedResult map[string]policy.BucketPolicy + expectedResult []bucketAccessPolicy }{ {bucketName, testCaseResult1}, } for i, testCase := range testCases { - args := &GetAllBucketPolicyArgs{BucketName: testCase.bucketName} - reply := &GetAllBucketPolicyRep{} - req, err := newTestWebRPCRequest("Web.GetAllBucketPolicy", authorization, args) + args := &ListAllBucketPoliciesArgs{BucketName: testCase.bucketName} + reply := &ListAllBucketPoliciesRep{} + req, err := newTestWebRPCRequest("Web.ListAllBucketPolicies", authorization, args) if err != nil { t.Fatalf("Test %d: Failed to create HTTP request: %v", i+1, err) }