summaryrefslogtreecommitdiff
path: root/swiftclient/utils.py
diff options
context:
space:
mode:
authorAlistair Coles <alistair.coles@hpe.com>2016-09-08 14:15:40 +0100
committerAlistair Coles <alistair.coles@hpe.com>2016-09-14 16:24:22 +0100
commit4c955751d340a8f71a2eebdb3c58d90b36874a66 (patch)
tree125940417cca382c0a34804aa53a16685fe0cf0c /swiftclient/utils.py
parent89ff29e788479334c218801beb0538b4a6bddf23 (diff)
downloadpython-swiftclient-4c955751d340a8f71a2eebdb3c58d90b36874a66.tar.gz
Make tempurl command check for valid object path
If the supplied path is not of the form /v1/a/c/o then swift tempurl subcommand will now return an error message. Also removes redundant check for seconds parameter being an int from shell.py because the same check is made when calling utils.generate_temp_url. Drive-by fix for missing param definition for generate_temp_url. Change-Id: I41f4389948b01fadaa5fc4939ea12e0ed2167345 Related-Change: I0fb2ce125fe12d660e4deb778265016bdd5ff31b
Diffstat (limited to 'swiftclient/utils.py')
-rw-r--r--swiftclient/utils.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
index d394283..2e727ad 100644
--- a/swiftclient/utils.py
+++ b/swiftclient/utils.py
@@ -68,14 +68,20 @@ def generate_temp_url(path, seconds, key, method, absolute=False):
:param path: The full path to the Swift object. Example:
/v1/AUTH_account/c/o.
- :param seconds: The amount of time in seconds the temporary URL will
- be valid for.
+ :param seconds: If absolute is False then this specifies the amount of time
+ in seconds for which the temporary URL will be valid. If absolute is
+ True then this specifies an absolute time at which the temporary URL
+ will expire.
:param key: The secret temporary URL key set on the Swift
cluster. To set a key, run 'swift post -m
"Temp-URL-Key: <substitute tempurl key here>"'
:param method: A HTTP method, typically either GET or PUT, to allow
for this temporary URL.
- :raises: ValueError if seconds is not a positive integer
+ :param absolute: if True then the seconds parameter is interpreted as an
+ absolute Unix time, otherwise seconds is interpreted as a relative time
+ offset from current time.
+ :raises: ValueError if seconds is not a positive integer or path is not to
+ an object.
:raises: TypeError if seconds is not an integer
:return: the path portion of a temporary URL
"""
@@ -94,6 +100,10 @@ def generate_temp_url(path, seconds, key, method, absolute=False):
else:
path_for_body = path
+ parts = path_for_body.split('/', 4)
+ if len(parts) != 5 or parts[0] or not all(parts[1:]):
+ raise ValueError('path must be full path to an object e.g. /v1/a/c/o')
+
standard_methods = ['GET', 'PUT', 'HEAD', 'POST', 'DELETE']
if method.upper() not in standard_methods:
logger = logging.getLogger("swiftclient")