Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import hmac
from hashlib import sha1
from sys import argv
from time import time
if len(argv) != 5:
print 'Syntax: <method> <url> <seconds> <key>'
print 'Example: GET' \
'MossoCloudFS_12345678-9abc-def0-1234-56789abcdef0/' \
'container/my_cat.jpg 60 my_shared_secret_key'
method, url, seconds, key = argv[1:]
method = method.upper()
base_url, object_path = url.split('/v1/')
object_path = '/v1/' + object_path
seconds = int(seconds)
expires = int(time() + seconds)
hmac_body = '%s\n%s\n%s' % (method, expires, object_path)
sig =, hmac_body, sha1).hexdigest()
print '%s%s?temp_url_sig=%sAMP;temp_url_expires=%s' % \
(base_url, object_path, sig, expires)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment