Skip to content

Commit

Permalink
canonical_string refactoring + fix typing in middleware comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vitoordaz committed Jun 18, 2013
1 parent 1216309 commit 3dbae14
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions swift3/middleware.py
Expand Up @@ -16,7 +16,7 @@
"""
The swift3 middleware will emulate the S3 REST api on top of swift.
The following opperations are currently supported:
The following operations are currently supported:
* GET Service
* DELETE Bucket
Expand Down Expand Up @@ -75,6 +75,14 @@

MAX_BUCKET_LISTING = 1000

# List of sub-resources that must be maintained as part of the HMAC
# signature string.
ALLOWED_SUB_RESOURCES = sorted([
'acl', 'delete', 'lifecycle', 'location', 'logging', 'notification',
'partNumber', 'policy', 'requestPayment', 'torrent', 'uploads', 'uploadId',
'versionId', 'versioning', 'versions ', 'website'
])


def get_err_response(code):
"""
Expand Down Expand Up @@ -274,29 +282,12 @@ def canonical_string(req):
path += '?' + req.query_string
if '?' in path:
path, args = path.split('?', 1)
qstr = ''
qdict = dict(urlparse.parse_qsl(args, keep_blank_values=True))
#
# List of sub-resources that must be maintained as part of the HMAC
# signature string.
#
keywords = sorted(['acl', 'delete', 'lifecycle', 'location', 'logging',
'notification', 'partNumber', 'policy',
'requestPayment', 'torrent', 'uploads', 'uploadId',
'versionId', 'versioning', 'versions ', 'website'])
for key in qdict:
if key in keywords:
newstr = key
if qdict[key]:
newstr = newstr + '=%s' % qdict[key]

if qstr == '':
qstr = newstr
else:
qstr = qstr + '&%s' % newstr

if qstr != '':
return "%s%s?%s" % (buf, path, qstr)
params = []
for key, value in urlparse.parse_qsl(args, keep_blank_values=True):
if key in ALLOWED_SUB_RESOURCES:
params.append('%s=%s' % (key, value) if value else key)
if params:
return '%s%s?%s' % (buf, path, '&'.join(params))

return buf + path

Expand Down

0 comments on commit 3dbae14

Please sign in to comment.