Refactor bucket delete and bucket policy (#5580)

This commit adds the bucket delete and bucket policy functionalities
to the browser.

Part of rewriting the browser code to follow best practices and
guidelines of React (issues #5409 and #5410)

The backend code has been modified by @krishnasrinivas to prevent
issue #4498 from occuring. The relevant changes have been made to the
code according to the latest commit and the unit tests in the backend.
This commit also addresses issue #5449.
This commit is contained in:
Kaan Kabalak
2018-02-27 19:14:49 -08:00
committed by Harshavardhana
parent 416841869a
commit a6adef0bdf
23 changed files with 836 additions and 204 deletions

View File

@@ -280,7 +280,7 @@ func (h minioReservedBucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
default:
// For all other requests reject access to reserved
// buckets
bucketName, _ := urlPath2BucketObjectName(r.URL)
bucketName, _ := urlPath2BucketObjectName(r.URL.Path)
if isMinioReservedBucket(bucketName) || isMinioMetaBucket(bucketName) {
writeErrorResponse(w, ErrAllAccessDisabled, r.URL)
return
@@ -439,7 +439,7 @@ var notimplementedObjectResourceNames = map[string]bool{
// Resource handler ServeHTTP() wrapper
func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
bucketName, objectName := urlPath2BucketObjectName(r.URL)
bucketName, objectName := urlPath2BucketObjectName(r.URL.Path)
// If bucketName is present and not objectName check for bucket level resource queries.
if bucketName != "" && objectName == "" {

View File

@@ -62,14 +62,9 @@ func cloneHeader(h http.Header) http.Header {
}
// Convert url path into bucket and object name.
func urlPath2BucketObjectName(u *url.URL) (bucketName, objectName string) {
if u == nil {
// Empty url, return bucket and object names.
return
}
func urlPath2BucketObjectName(path string) (bucketName, objectName string) {
// Trim any preceding slash separator.
urlPath := strings.TrimPrefix(u.Path, slashSeparator)
urlPath := strings.TrimPrefix(path, slashSeparator)
// Split urlpath using slash separator into a given number of
// expected tokens.

View File

@@ -205,12 +205,6 @@ func TestURL2BucketObjectName(t *testing.T) {
bucket: "bucket",
object: "///object////",
},
// Test case 8 url is not allocated.
{
u: nil,
bucket: "",
object: "",
},
// Test case 9 url path is empty.
{
u: &url.URL{},
@@ -221,7 +215,7 @@ func TestURL2BucketObjectName(t *testing.T) {
// Validate all test cases.
for i, testCase := range testCases {
bucketName, objectName := urlPath2BucketObjectName(testCase.u)
bucketName, objectName := urlPath2BucketObjectName(testCase.u.Path)
if bucketName != testCase.bucket {
t.Errorf("Test %d: failed expected bucket name \"%s\", got \"%s\"", i+1, testCase.bucket, bucketName)
}

View File

@@ -741,6 +741,7 @@ type ListAllBucketPoliciesArgs struct {
// BucketAccessPolicy - Collection of canned bucket policy at a given prefix.
type BucketAccessPolicy struct {
Bucket string `json:"bucket"`
Prefix string `json:"prefix"`
Policy policy.BucketPolicy `json:"policy"`
}
@@ -770,8 +771,11 @@ func (web *webAPIHandlers) ListAllBucketPolicies(r *http.Request, args *ListAllB
}
reply.UIVersion = browser.UIVersion
for prefix, policy := range policy.GetPolicies(policyInfo.Statements, args.BucketName, "") {
bucketName, objectPrefix := urlPath2BucketObjectName(prefix)
objectPrefix = strings.TrimSuffix(objectPrefix, "*")
reply.Policies = append(reply.Policies, BucketAccessPolicy{
Prefix: prefix,
Bucket: bucketName,
Prefix: objectPrefix,
Policy: policy,
})
}
@@ -822,6 +826,23 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic
return nil
}
_, err = json.Marshal(policyInfo)
if err != nil {
return toJSONError(err)
}
// Parse check bucket policy.
if s3Error := checkBucketPolicyResources(args.BucketName, policyInfo); s3Error != ErrNone {
apiErr := getAPIError(s3Error)
var err error
if apiErr.Code == "XMinioPolicyNesting" {
err = PolicyNesting{}
} else {
err = fmt.Errorf(apiErr.Description)
}
return toJSONError(err, args.BucketName)
}
// Parse validate and save bucket policy.
if err := objectAPI.SetBucketPolicy(context.Background(), args.BucketName, policyInfo); err != nil {
return toJSONError(err, args.BucketName)

View File

@@ -1385,7 +1385,8 @@ func testWebListAllBucketPoliciesHandler(obj ObjectLayer, instanceType string, t
}
testCaseResult1 := []BucketAccessPolicy{{
Prefix: bucketName + "/hello*",
Bucket: bucketName,
Prefix: "hello",
Policy: policy.BucketPolicyReadWrite,
}}
testCases := []struct {