summaryrefslogtreecommitdiff
path: root/swiftclient/utils.py
diff options
context:
space:
mode:
authorZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
committerZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
commit52d39bebc11979fa1be5090ff75466710638e561 (patch)
treef700b14751375eadd84f2688a73f1e930a24930d /swiftclient/utils.py
parent93666bb84abc1edc36fbb3ef5ec194cf774e4826 (diff)
downloadpython-swiftclient-52d39bebc11979fa1be5090ff75466710638e561.tar.gz
absolute expiry option for tempURL generation
The `tempurl` subcommand's second positional argument is called `seconds` and has heretofore interpreted as the number of seconds for which the tempURL should be valid, counting from the moment of running the command. This is indeed a common, if not the most common, use-case. But some users, occasionally, might want to generate a tempURL that expires at some particular ("absolute") time, rather than a particular amount of time relative to the moment of happening to run the command. (One might make an analogy to the way in which Swift's expiring object support supports an `X-Delete-At` header in addition to `X-Delete-After`—and it's the former that must be regarded as ontologically prior.) Thus, this commit adds an `--absolute` optional argument to the `tempurl` subcommand; if present, the `seconds` argument will be interpreted as a Unix timestamp of when the tempURL should be expire, rather than a duration for which the tempURL should be valid starting from "now". Change-Id: If9ded96f2799800958d5063127f3de812f50ef06
Diffstat (limited to 'swiftclient/utils.py')
-rw-r--r--swiftclient/utils.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
index 6ff6259..8316a8f 100644
--- a/swiftclient/utils.py
+++ b/swiftclient/utils.py
@@ -65,8 +65,8 @@ def prt_bytes(bytes, human_flag):
return bytes
-def generate_temp_url(path, seconds, key, method):
- """ Generates a temporary URL that gives unauthenticated access to the
+def generate_temp_url(path, seconds, key, method, absolute=False):
+ """Generates a temporary URL that gives unauthenticated access to the
Swift object.
:param path: The full path to the Swift object. Example:
@@ -85,7 +85,10 @@ def generate_temp_url(path, seconds, key, method):
if seconds < 0:
raise ValueError('seconds must be a positive integer')
try:
- expiration = int(time.time() + seconds)
+ if not absolute:
+ expiration = int(time.time() + seconds)
+ else:
+ expiration = int(seconds)
except TypeError:
raise TypeError('seconds must be an integer')