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
This commit is contained in:
1 changed files with 8 additions and 3 deletions
@@ -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 <method> <seconds> <path> <key>' % 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)
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.