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 support for Unsigned Requests #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ debug output
##### `--validate`
(obsolete) validate lookup operation

##### `--no-sign-request`
Makes unsigned request.

##### `-D, --delete-removed`
delete remote files that do not exist in source after sync

Expand Down
24 changes: 16 additions & 8 deletions s4cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,8 @@ def __init__(self, opt, aws_access_key_id=None, aws_secret_access_key=None):
for each method we are going to call.
'''
self.opt = opt
if (aws_access_key_id is not None) and (aws_secret_access_key is not None):
self.client = self.boto3.client('s3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=opt.endpoint_url)
else:
self.client = self.boto3.client('s3', endpoint_url=opt.endpoint_url)

client_params = self._get_client_params(aws_access_key_id, aws_secret_access_key)
self.client = self.boto3.client('s3', **client_params)
# Cache the result so we don't have to recalculate.
self.legal_params = {}
for method in BotoClient.ALLOWED_CLIENT_METHODS:
Expand All @@ -407,6 +401,16 @@ def wrapped_method(*args, **kargs):

return super(BotoClient, self).__getattribute__(method)

def _get_client_params(self, aws_access_key_id=None, aws_secret_access_key=None):
client_params = {'endpoint_url': self.opt.endpoint_url}
if self.opt.no_sign_request:
client_params['config'] = self.botocore.config.Config(signature_version=self.botocore.UNSIGNED)
if (aws_access_key_id is not None) and (aws_secret_access_key is not None):
client_params['aws_access_key_id'] = aws_access_key_id
client_params['aws_secret_access_key'] = aws_secret_access_key

return client_params

def get_legal_params(self, method):
'''Given a API name, list all legal parameters using boto3 service model.'''
if method not in self.client.meta.method_to_api_mapping:
Expand Down Expand Up @@ -1878,6 +1882,10 @@ def main():
parser.add_option(
'--validate', help='(obsolete) validate lookup operation', dest='validate',
action='store_true', default=False)
parser.add_option(
'--no-sign-request',
help='unsigned requests would be made if set.', dest='no_sign_request',
action='store_true', default=False)
parser.add_option(
'-D', '--delete-removed',
help='delete remote files that do not exist in source after sync',
Expand Down