minio: Replace 'bucket already exists' error by 'bucket already owned by you'. (#1465)

S3 API returns BucketAlreadyExists error when some another user has such bucket.
If user that creates the bucket already has it, s3 returns BucketAlreadyOwnedByYou.
As minio has only one user, it should behave accordingly.
Otherwise it causes failures in the applications that ignore creation of already existing bucket in the account, but fail when bucket name is used by someone else.
This commit is contained in:
Yurii 2016-05-03 13:19:04 +03:00 committed by Harshavardhana
parent 7ae40eb1bb
commit bba5468368
3 changed files with 8 additions and 2 deletions

View file

@ -104,6 +104,7 @@ const (
ErrMissingDateHeader
ErrInvalidQuerySignatureAlgo
ErrInvalidQueryParams
ErrBucketAlreadyOwnedByYou
// Add new error codes here.
// Extended errors.
@ -409,6 +410,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{
Description: "Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.",
HTTPStatusCode: http.StatusBadRequest,
},
ErrBucketAlreadyOwnedByYou: {
Code: "BucketAlreadyOwnedByYou",
Description: "Your previous request to create the named bucket succeeded and you already own it.",
HTTPStatusCode: http.StatusConflict,
},
// Add your error structure here.
}

View file

@ -499,7 +499,7 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req
case BucketNameInvalid:
writeErrorResponse(w, r, ErrInvalidBucketName, r.URL.Path)
case BucketExists:
writeErrorResponse(w, r, ErrBucketAlreadyExists, r.URL.Path)
writeErrorResponse(w, r, ErrBucketAlreadyOwnedByYou, r.URL.Path)
default:
writeErrorResponse(w, r, ErrInternalError, r.URL.Path)
}

View file

@ -963,7 +963,7 @@ func (s *MyAPISuite) TestPutBucketErrors(c *C) {
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "BucketAlreadyExists", "The requested bucket name is not available.", http.StatusConflict)
verifyError(c, response, "BucketAlreadyOwnedByYou", "Your previous request to create the named bucket succeeded and you already own it.", http.StatusConflict)
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/putbucket?acl", 0, nil)
c.Assert(err, IsNil)