Skip to content

Resolves #12. Adds support for path-style URLs on top of the already… #16

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 27 additions & 8 deletions awsauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,29 @@ def get_signature(self, r):

def get_canonical_string(self, url, headers, method):
parsedurl = urlparse(url)
objectkey = parsedurl.path[1:]
query_args = sorted(parsedurl.query.split('&'))

bucket = parsedurl.netloc[:-len(self.service_base_url)]
if len(bucket) > 1:
# remove last dot
bucket = bucket[:-1]
is_virtual_hosted_style_url = parsedurl.netloc.endswith(
'.s3.amazonaws.com')

if is_virtual_hosted_style_url:
objectkey = parsedurl.path[1:]
bucket = parsedurl.netloc[:-len(self.service_base_url)]
if len(bucket) > 1:
# remove last dot
bucket = bucket[:-1]
else:
# path-style URL
# examples:
# /mybucket
# /mybucket/object
# /mybucket/folder/object
path_split = parsedurl.path[1:].split('/', 1)
bucket = ''
objectkey = ''
if len(path_split) > 0:
bucket = path_split[0]
if len(path_split) > 1:
objectkey = path_split[1]

interesting_headers = {
'content-md5': '',
Expand Down Expand Up @@ -107,8 +123,11 @@ def get_canonical_string(self, url, headers, method):
if bucket != '':
buf += '/%s' % bucket

# add the objectkey. even if it doesn't exist, add the slash
buf += '/%s' % objectkey
# add the objectkey.
# If this is a virtual-hosted-style URL
# add the slash even if the objectkey doesn't exist
if objectkey or is_virtual_hosted_style_url:
buf += '/%s' % objectkey

params_found = False

Expand Down