Created
September 3, 2013 05:09
-
-
Save christophchamp/6419896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html | |
# https://community.rackspace.com/developers/f/7/t/798 | |
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 https://storage101.dfw1.clouddrive.com/v1/' \ | |
'MossoCloudFS_12345678-9abc-def0-1234-56789abcdef0/' \ | |
'container/my_cat.jpg 60 my_shared_secret_key' | |
else: | |
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.new(key, 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