Skip to content
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

Add messaging on how to enable sigv4 for s3 #1638

Merged
merged 1 commit into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion awscli/customizations/s3errormsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# language governing permissions and limitations under the License.
"""Give better S3 error messages.
"""
from awscli.customizations import utils


REGION_ERROR_MSG = (
Expand All @@ -23,6 +22,11 @@
'running "aws s3api get-bucket-location --bucket BUCKET".'
)

ENABLE_SIGV4_MSG = (
' You can enable AWS Signature Version 4 by running the command: \n'
'aws configure set s3.signature_version s3v4'
)


def register_s3_error_msg(event_handlers):
event_handlers.register('after-call.s3', enhance_error_msg)
Expand All @@ -45,6 +49,8 @@ def enhance_error_msg(parsed, **kwargs):
new_message = message[:-1] + ': %s\n' % endpoint
new_message += REGION_ERROR_MSG
parsed['Error']['Message'] = new_message
elif _is_kms_sigv4_error_message(parsed):
parsed['Error']['Message'] += ENABLE_SIGV4_MSG


def _is_sigv4_error_message(parsed):
Expand All @@ -54,3 +60,8 @@ def _is_sigv4_error_message(parsed):

def _is_permanent_redirect_message(parsed):
return parsed.get('Error', {}).get('Code', '') == 'PermanentRedirect'


def _is_kms_sigv4_error_message(parsed):
return ('AWS KMS managed keys require AWS Signature Version 4' in
parsed.get('Error', {}).get('Message', ''))
17 changes: 17 additions & 0 deletions tests/unit/customizations/test_s3errormsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ def test_301_error_message(self):
error_message = parsed['Error']['Message']
self.assertIn('myendpoint', error_message)

def test_kms_sigv4_error_message(self):
parsed = {
'Error': {
'Message': (
'Requests specifying Server Side Encryption with '
'AWS KMS managed keys require AWS Signature Version 4.')
}
}
s3errormsg.enhance_error_msg(parsed)
# We should say how you enable it.
self.assertIn('You can enable AWS Signature Version 4',
parsed['Error']['Message'])
# We should mention the command that needs to be run.
self.assertIn(
'aws configure set s3.signature_version s3v4',
parsed['Error']['Message'])

def test_error_message_not_enhanced(self):
parsed = {
'Error': {
Expand Down