From b7659bee269db9866629824ebf968e1c706081a1 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Fri, 2 May 2014 20:11:12 -0700 Subject: [PATCH] Add --quoted option to swift-temp-url If you have a path with special characters it may be easier to hand them to swift-temp-url prequoted than try to escape them on the command line. By the time common.middleware.tempurl gets ahold of the path it's unquoted so we do the same before calculating the hmac but still use the pre-quoted path output to the commandline. Change-Id: Ia1a9666e487b1e70e4db7cd597bc6a1027e3e918 --- bin/swift-temp-url | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/swift-temp-url b/bin/swift-temp-url index 041c0129fa..1e728d1ad4 100755 --- a/bin/swift-temp-url +++ b/bin/swift-temp-url @@ -17,10 +17,11 @@ from hashlib import sha1 from os.path import basename from sys import argv, exit, stderr from time import time +import urllib if __name__ == '__main__': - if len(argv) != 5: + if len(argv) < 5: prog = basename(argv[0]) print 'Syntax: %s ' % prog print @@ -45,7 +46,7 @@ if __name__ == '__main__': 'temp_url_sig=34d49efc32fe6e3082e411eeeb85bd8a&' \ 'temp_url_expires=1323482948' exit(1) - method, seconds, path, key = argv[1:] + method, seconds, path, key = argv[1:5] try: expires = int(time() + int(seconds)) except ValueError: @@ -64,6 +65,10 @@ if __name__ == '__main__': '(e.g. /v1/account/container/object).\n' % path) stderr.write( 'WARNING: Non-object paths will be rejected by tempurl.\n') - sig = hmac.new(key, '%s\n%s\n%s' % (method, expires, path), + if '--quoted' in argv[5:]: + real_path = urllib.unquote(path) + else: + real_path = path + sig = hmac.new(key, '%s\n%s\n%s' % (method, expires, real_path), sha1).hexdigest() print '%s?temp_url_sig=%s&temp_url_expires=%s' % (path, sig, expires)