Merge "Add --quoted option to swift-temp-url"

This commit is contained in:
Jenkins 2014-06-03 05:10:28 +00:00 committed by Gerrit Code Review
commit c384d76c57

View File

@ -17,10 +17,11 @@ from hashlib import sha1
from os.path import basename from os.path import basename
from sys import argv, exit, stderr from sys import argv, exit, stderr
from time import time from time import time
import urllib
if __name__ == '__main__': if __name__ == '__main__':
if len(argv) != 5: if len(argv) < 5:
prog = basename(argv[0]) prog = basename(argv[0])
print 'Syntax: %s <method> <seconds> <path> <key>' % prog print 'Syntax: %s <method> <seconds> <path> <key>' % prog
print print
@ -45,7 +46,7 @@ if __name__ == '__main__':
'temp_url_sig=34d49efc32fe6e3082e411eeeb85bd8a&' \ 'temp_url_sig=34d49efc32fe6e3082e411eeeb85bd8a&' \
'temp_url_expires=1323482948' 'temp_url_expires=1323482948'
exit(1) exit(1)
method, seconds, path, key = argv[1:] method, seconds, path, key = argv[1:5]
try: try:
expires = int(time() + int(seconds)) expires = int(time() + int(seconds))
except ValueError: except ValueError:
@ -64,6 +65,10 @@ if __name__ == '__main__':
'(e.g. /v1/account/container/object).\n' % path) '(e.g. /v1/account/container/object).\n' % path)
stderr.write( stderr.write(
'WARNING: Non-object paths will be rejected by tempurl.\n') '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() sha1).hexdigest()
print '%s?temp_url_sig=%s&temp_url_expires=%s' % (path, sig, expires) print '%s?temp_url_sig=%s&temp_url_expires=%s' % (path, sig, expires)