summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClay Gerrard <clay.gerrard@gmail.com>2014-05-02 20:11:12 -0700
committerClay Gerrard <clay.gerrard@gmail.com>2014-05-02 20:11:12 -0700
commitb7659bee269db9866629824ebf968e1c706081a1 (patch)
tree80a59d0c58fbe74e1680fdadf930515c001b6adb
parentf469d4214f0d60a02a2f03edf512ad22e17432d7 (diff)
downloadswift-b7659bee269db9866629824ebf968e1c706081a1.tar.gz
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
-rwxr-xr-xbin/swift-temp-url11
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/swift-temp-url b/bin/swift-temp-url
index 041c0129f..1e728d1ad 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 <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)