FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/awscli/customizations/s3errormsg.py at develop · ProGamerCode/aws-cli · GitHub
ProGamerCode
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
awscli
/
customizations
/
s3errormsg.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (54 loc) · 2.42 KB
Breadcrumbs
aws-cli
/
awscli
/
customizations
/
s3errormsg.py
Copy path
File metadata and controls
67 lines (54 loc) · 2.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Give better S3 error messages.
"""
REGION_ERROR_MSG
=
(
'You can fix this issue by explicitly providing the correct region '
'location using the --region argument, the AWS_DEFAULT_REGION '
'environment variable, or the region variable in the AWS CLI '
"configuration file. You can get the bucket's location by "
'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
)
def
enhance_error_msg
(
parsed
,
**
kwargs
):
if
parsed
is
None
or
'Error'
not
in
parsed
:
# There's no error message to enhance so we can continue.
return
if
_is_sigv4_error_message
(
parsed
):
message
=
(
'You are attempting to operate on a bucket in a region '
'that requires Signature Version 4. '
)
message
+=
REGION_ERROR_MSG
parsed
[
'Error'
][
'Message'
]
=
message
elif
_is_permanent_redirect_message
(
parsed
):
endpoint
=
parsed
[
'Error'
][
'Endpoint'
]
message
=
parsed
[
'Error'
][
'Message'
]
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
):
return
(
'Please use AWS4-HMAC-SHA256'
in
parsed
.
get
(
'Error'
, {}).
get
(
'Message'
,
''
))
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'
,
''
))
Back
|
FazBrowse Home
|
New Git URL