mirror of
https://github.com/minio/minio.git
synced 2025-03-29 00:33:42 -04:00
web: Simplify and rename GetAllBucketPolicy --> ListAllBucketPolicies. (#2778)
This commit is contained in:
parent
1c941fd787
commit
be0e06c0aa
@ -575,27 +575,31 @@ func (web *webAPIHandlers) GetBucketPolicy(r *http.Request, args *GetBucketPolic
|
|||||||
return &json2.Error{Message: err.Error()}
|
return &json2.Error{Message: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketPolicy := policy.GetPolicy(policyInfo.Statements, args.BucketName, args.Prefix)
|
|
||||||
|
|
||||||
reply.UIVersion = miniobrowser.UIVersion
|
reply.UIVersion = miniobrowser.UIVersion
|
||||||
reply.Policy = bucketPolicy
|
reply.Policy = policy.GetPolicy(policyInfo.Statements, args.BucketName, args.Prefix)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllBucketPolicyArgs - get all bucket policy args.
|
// ListAllBucketPoliciesArgs - get all bucket policies.
|
||||||
type GetAllBucketPolicyArgs struct {
|
type ListAllBucketPoliciesArgs struct {
|
||||||
BucketName string `json:"bucketName"`
|
BucketName string `json:"bucketName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllBucketPolicyRep - get all bucket policy reply.
|
// Collection of canned bucket policy at a given prefix.
|
||||||
type GetAllBucketPolicyRep struct {
|
type bucketAccessPolicy struct {
|
||||||
UIVersion string `json:"uiVersion"`
|
Prefix string `json:"prefix"`
|
||||||
Policies map[string]policy.BucketPolicy `json:"policies"`
|
Policy policy.BucketPolicy `json:"policy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllBucketPolicy - get all bucket policy.
|
// ListAllBucketPoliciesRep - get all bucket policy reply.
|
||||||
func (web *webAPIHandlers) GetAllBucketPolicy(r *http.Request, args *GetAllBucketPolicyArgs, reply *GetAllBucketPolicyRep) error {
|
type ListAllBucketPoliciesRep struct {
|
||||||
|
UIVersion string `json:"uiVersion"`
|
||||||
|
Policies []bucketAccessPolicy `json:"policies"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetllBucketPolicy - get all bucket policy.
|
||||||
|
func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllBucketPoliciesArgs, reply *ListAllBucketPoliciesRep) error {
|
||||||
if !isJWTReqAuthenticated(r) {
|
if !isJWTReqAuthenticated(r) {
|
||||||
return &json2.Error{Message: "Unauthorized request"}
|
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()}
|
return &json2.Error{Message: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
policies := policy.GetPolicies(policyInfo.Statements, args.BucketName)
|
|
||||||
|
|
||||||
reply.UIVersion = miniobrowser.UIVersion
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,13 +868,13 @@ func testWebGetBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper for calling GetAllBucketPolicy Handler
|
// Wrapper for calling ListAllBucketPolicies Handler
|
||||||
func TestWebHandlerGetAllBucketPolicyHandler(t *testing.T) {
|
func TestWebHandlerListAllBucketPoliciesHandler(t *testing.T) {
|
||||||
ExecObjectLayerTest(t, testWebGetAllBucketPolicyHandler)
|
ExecObjectLayerTest(t, testWebListAllBucketPoliciesHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testWebGetAllBucketPolicyHandler - Test GetAllBucketPolicy web handler
|
// testWebListAllBucketPoliciesHandler - Test ListAllBucketPolicies web handler
|
||||||
func testWebGetAllBucketPolicyHandler(obj ObjectLayer, instanceType string, t TestErrHandler) {
|
func testWebListAllBucketPoliciesHandler(obj ObjectLayer, instanceType string, t TestErrHandler) {
|
||||||
// Register the API end points with XL/FS object layer.
|
// Register the API end points with XL/FS object layer.
|
||||||
apiRouter := initTestWebRPCEndPoint(obj)
|
apiRouter := initTestWebRPCEndPoint(obj)
|
||||||
// initialize the server and obtain the credentials and root.
|
// 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)
|
t.Fatal("Unexpected error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testCaseResult1 := make(map[string]policy.BucketPolicy)
|
testCaseResult1 := []bucketAccessPolicy{{
|
||||||
testCaseResult1[bucketName+"/hello*"] = policy.BucketPolicyReadWrite
|
Prefix: bucketName + "/hello*",
|
||||||
|
Policy: policy.BucketPolicyReadWrite,
|
||||||
|
}}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
bucketName string
|
bucketName string
|
||||||
expectedResult map[string]policy.BucketPolicy
|
expectedResult []bucketAccessPolicy
|
||||||
}{
|
}{
|
||||||
{bucketName, testCaseResult1},
|
{bucketName, testCaseResult1},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
args := &GetAllBucketPolicyArgs{BucketName: testCase.bucketName}
|
args := &ListAllBucketPoliciesArgs{BucketName: testCase.bucketName}
|
||||||
reply := &GetAllBucketPolicyRep{}
|
reply := &ListAllBucketPoliciesRep{}
|
||||||
req, err := newTestWebRPCRequest("Web.GetAllBucketPolicy", authorization, args)
|
req, err := newTestWebRPCRequest("Web.ListAllBucketPolicies", authorization, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %d: Failed to create HTTP request: <ERROR> %v", i+1, err)
|
t.Fatalf("Test %d: Failed to create HTTP request: <ERROR> %v", i+1, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user