|
|
@ -802,6 +802,13 @@ func (web *webAPIHandlers) SetBucketPolicy(r *http.Request, args *SetBucketPolic |
|
|
|
policyInfo.Statements = policy.SetPolicy(policyInfo.Statements, bucketP, args.BucketName, args.Prefix) |
|
|
|
policyInfo.Statements = policy.SetPolicy(policyInfo.Statements, bucketP, args.BucketName, args.Prefix) |
|
|
|
switch g := objectAPI.(type) { |
|
|
|
switch g := objectAPI.(type) { |
|
|
|
case GatewayLayer: |
|
|
|
case GatewayLayer: |
|
|
|
|
|
|
|
if len(policyInfo.Statements) == 0 { |
|
|
|
|
|
|
|
err = g.DeleteBucketPolicies(args.BucketName) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return toJSONError(err, args.BucketName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
err = g.SetBucketPolicies(args.BucketName, policyInfo) |
|
|
|
err = g.SetBucketPolicies(args.BucketName, policyInfo) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return toJSONError(err) |
|
|
|
return toJSONError(err) |
|
|
@ -1011,39 +1018,46 @@ func toWebAPIError(err error) APIError { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Convert error type to api error code.
|
|
|
|
// Convert error type to api error code.
|
|
|
|
var apiErrCode APIErrorCode |
|
|
|
|
|
|
|
switch err.(type) { |
|
|
|
switch err.(type) { |
|
|
|
case StorageFull: |
|
|
|
case StorageFull: |
|
|
|
apiErrCode = ErrStorageFull |
|
|
|
return getAPIError(ErrStorageFull) |
|
|
|
case BucketNotFound: |
|
|
|
case BucketNotFound: |
|
|
|
apiErrCode = ErrNoSuchBucket |
|
|
|
return getAPIError(ErrNoSuchBucket) |
|
|
|
case BucketExists: |
|
|
|
case BucketExists: |
|
|
|
apiErrCode = ErrBucketAlreadyOwnedByYou |
|
|
|
return getAPIError(ErrBucketAlreadyOwnedByYou) |
|
|
|
case BucketNameInvalid: |
|
|
|
case BucketNameInvalid: |
|
|
|
apiErrCode = ErrInvalidBucketName |
|
|
|
return getAPIError(ErrInvalidBucketName) |
|
|
|
case BadDigest: |
|
|
|
case BadDigest: |
|
|
|
apiErrCode = ErrBadDigest |
|
|
|
return getAPIError(ErrBadDigest) |
|
|
|
case IncompleteBody: |
|
|
|
case IncompleteBody: |
|
|
|
apiErrCode = ErrIncompleteBody |
|
|
|
return getAPIError(ErrIncompleteBody) |
|
|
|
case ObjectExistsAsDirectory: |
|
|
|
case ObjectExistsAsDirectory: |
|
|
|
apiErrCode = ErrObjectExistsAsDirectory |
|
|
|
return getAPIError(ErrObjectExistsAsDirectory) |
|
|
|
case ObjectNotFound: |
|
|
|
case ObjectNotFound: |
|
|
|
apiErrCode = ErrNoSuchKey |
|
|
|
return getAPIError(ErrNoSuchKey) |
|
|
|
case ObjectNameInvalid: |
|
|
|
case ObjectNameInvalid: |
|
|
|
apiErrCode = ErrNoSuchKey |
|
|
|
return getAPIError(ErrNoSuchKey) |
|
|
|
case InsufficientWriteQuorum: |
|
|
|
case InsufficientWriteQuorum: |
|
|
|
apiErrCode = ErrWriteQuorum |
|
|
|
return getAPIError(ErrWriteQuorum) |
|
|
|
case InsufficientReadQuorum: |
|
|
|
case InsufficientReadQuorum: |
|
|
|
apiErrCode = ErrReadQuorum |
|
|
|
return getAPIError(ErrReadQuorum) |
|
|
|
case PolicyNesting: |
|
|
|
case PolicyNesting: |
|
|
|
apiErrCode = ErrPolicyNesting |
|
|
|
return getAPIError(ErrPolicyNesting) |
|
|
|
default: |
|
|
|
case NotImplemented: |
|
|
|
// Log unexpected and unhandled errors.
|
|
|
|
return APIError{ |
|
|
|
errorIf(err, errUnexpected.Error()) |
|
|
|
Code: "NotImplemented", |
|
|
|
apiErrCode = ErrInternalError |
|
|
|
HTTPStatusCode: http.StatusBadRequest, |
|
|
|
|
|
|
|
Description: "Functionality not implemented", |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log unexpected and unhandled errors.
|
|
|
|
|
|
|
|
errorIf(err, errUnexpected.Error()) |
|
|
|
|
|
|
|
return APIError{ |
|
|
|
|
|
|
|
Code: "InternalError", |
|
|
|
|
|
|
|
HTTPStatusCode: http.StatusInternalServerError, |
|
|
|
|
|
|
|
Description: err.Error(), |
|
|
|
} |
|
|
|
} |
|
|
|
apiErr := getAPIError(apiErrCode) |
|
|
|
|
|
|
|
return apiErr |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// writeWebErrorResponse - set HTTP status code and write error description to the body.
|
|
|
|
// writeWebErrorResponse - set HTTP status code and write error description to the body.
|
|
|
|