-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport #1233 to 2.0 #1253
Closed
Closed
Backport #1233 to 2.0 #1253
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,9 @@ | |
|
||
-type error_reason() :: atom() | ||
| {'riak_connect_failed', term()} | ||
| {'malformed_policy_version', string()}. | ||
| {'malformed_policy_version', string()} | ||
| {'invalid_argument', string()} | ||
| {'key_too_long', pos_integer()}. | ||
|
||
-spec error_message(error_reason()) -> string(). | ||
error_message(invalid_access_key_id) -> | ||
|
@@ -61,6 +63,8 @@ error_message(bucket_already_exists) -> | |
"The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again."; | ||
error_message(toomanybuckets) -> | ||
"You have attempted to create more buckets than allowed"; | ||
error_message({key_too_long, _}) -> | ||
"Your key is too long"; | ||
error_message(user_already_exists) -> | ||
"The specified email address has already been registered. Email addresses must be unique among all users of the system. Please try again with a different email address."; | ||
error_message(entity_too_large) -> | ||
|
@@ -115,6 +119,7 @@ error_code(reqtime_tooskewed) -> "RequestTimeTooSkewed"; | |
error_code(bucket_not_empty) -> "BucketNotEmpty"; | ||
error_code(bucket_already_exists) -> "BucketAlreadyExists"; | ||
error_code(toomanybuckets) -> "TooManyBuckets"; | ||
error_code({key_too_long, _}) -> "KeyTooLongError"; | ||
error_code(user_already_exists) -> "UserAlreadyExists"; | ||
error_code(entity_too_large) -> "EntityTooLarge"; | ||
error_code(entity_too_small) -> "EntityTooSmall"; | ||
|
@@ -158,14 +163,16 @@ error_code(ErrorName) -> | |
%% http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html | ||
|
||
-spec status_code(error_reason()) -> pos_integer(). | ||
status_code(invalid_access_key_id) -> 403; | ||
status_code(invalid_email_address) -> 400; | ||
status_code(access_denied) -> 403; | ||
status_code(reqtime_tooskewed) -> 403; | ||
status_code(bucket_not_empty) -> 409; | ||
status_code(bucket_already_exists) -> 409; | ||
status_code(user_already_exists) -> 409; | ||
status_code(toomanybuckets) -> 400; | ||
status_code(invalid_access_key_id) -> 403; | ||
status_code(invalid_email_address) -> 400; | ||
status_code(access_denied) -> 403; | ||
status_code(copy_source_access_denied) -> 403; | ||
status_code(reqtime_tooskewed) -> 403; | ||
status_code(bucket_not_empty) -> 409; | ||
status_code(bucket_already_exists) -> 409; | ||
status_code(user_already_exists) -> 409; | ||
status_code(toomanybuckets) -> 400; | ||
status_code({key_too_long, _}) -> 400; | ||
%% yes, 400, really, not 413 | ||
status_code(entity_too_large) -> 400; | ||
status_code(entity_too_small) -> 400; | ||
|
@@ -240,6 +247,10 @@ api_error({Tag, _}=Error, RD, Ctx) | |
Ctx); | ||
api_error({toomanybuckets, Current, BucketLimit}, RD, Ctx) -> | ||
toomanybuckets_response(Current, BucketLimit, RD, Ctx); | ||
api_error({invalid_argument, Name, Value}, RD, Ctx) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This clause is not called. |
||
invalid_argument_response(Name, Value, RD, Ctx); | ||
api_error({key_too_long, Len}, RD, Ctx) -> | ||
key_too_long(Len, RD, Ctx); | ||
api_error({error, Reason}, RD, Ctx) -> | ||
api_error(Reason, RD, Ctx). | ||
|
||
|
@@ -267,6 +278,30 @@ toomanybuckets_response(Current,BucketLimit,RD,Ctx) -> | |
Body = riak_cs_xml:to_xml([XmlDoc]), | ||
respond(status_code(toomanybuckets), Body, RD, Ctx). | ||
|
||
invalid_argument_response(Name, Value, RD, Ctx) -> | ||
XmlDoc = {'Error', | ||
[ | ||
{'Code', [error_code(invalid_argument)]}, | ||
{'Message', [error_message({invalid_argument, Name})]}, | ||
{'ArgumentName', [Name]}, | ||
{'ArgumentValue', [Value]}, | ||
{'RequestId', [""]} | ||
]}, | ||
Body = riak_cs_xml:to_xml([XmlDoc]), | ||
respond(status_code(invalid_argument), Body, RD, Ctx). | ||
|
||
key_too_long(Len, RD, Ctx) -> | ||
XmlDoc = {'Error', | ||
[ | ||
{'Code', [error_code({key_too_long, Len})]}, | ||
{'Message', [error_message({key_too_long, Len})]}, | ||
{'Size', [Len]}, | ||
{'MaxSizeAllowed', [riak_cs_config:max_key_length()]}, | ||
{'RequestId', [""]} | ||
]}, | ||
Body = riak_cs_xml:to_xml([XmlDoc]), | ||
respond(status_code(invalid_argument), Body, RD, Ctx). | ||
|
||
copy_object_response(Manifest, RD, Ctx) -> | ||
copy_response(Manifest, 'CopyObjectResult', RD, Ctx). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,23 @@ init(Ctx) -> | |
{ok, Ctx#context{local_context=#key_context{}}}. | ||
|
||
-spec malformed_request(#wm_reqdata{}, #context{}) -> {false, #wm_reqdata{}, #context{}}. | ||
malformed_request(RD, Ctx) -> | ||
ContextWithKey = riak_cs_wm_utils:extract_key(RD, Ctx), | ||
case riak_cs_wm_utils:has_canned_acl_and_header_grant(RD) of | ||
true -> | ||
riak_cs_s3_response:api_error(canned_acl_and_header_grant, | ||
malformed_request(RD, #context{response_module=ResponseMod} = Ctx) -> | ||
case riak_cs_wm_utils:extract_key(RD, Ctx) of | ||
{error, Reason} -> | ||
ResponseMod:api_error(Reason, RD, Ctx); | ||
{ok, ContextWithKey} -> | ||
case riak_cs_wm_utils:has_canned_acl_and_header_grant(RD) of | ||
true -> | ||
ResponseMod:api_error(canned_acl_and_header_grant, | ||
RD, ContextWithKey); | ||
false -> | ||
{false, RD, ContextWithKey} | ||
false -> | ||
case riak_cs_copy_object:malformed_request(RD) of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. xref complains about this line. |
||
{true, Reason} -> | ||
ResponseMod:api_error(Reason, RD, ContextWithKey); | ||
false -> | ||
{false, RD, ContextWithKey} | ||
end | ||
end | ||
end. | ||
|
||
%% @doc Get the type of access requested and the manifest with the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error atom is not used anywhere else?