Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created March 1, 2013 15:32
Show Gist options
  • Save chmouel/5065414 to your computer and use it in GitHub Desktop.
Save chmouel/5065414 to your computer and use it in GitHub Desktop.
# test_client.py
import hmac
from time import time
from hashlib import sha1
import requests
MODE = "VM"
#var
CONF = {
'VM': {
'account_formdata_key': 'foobar',
'account': 'c130b4e303864d0a9e52f02432030d87',
'container': 'foobar',
'host': 'vm:8080',
'htmethod': 'http',
'object': 'foo.txt',
}
}
#const
max_file_size = 1073741824
seconds = 86400
sample_file = "/tmp/s"
#other
expires = int(time() + int(seconds))
path = "v1/AUTH_%(account)s/%(container)s/%(object)s" % CONF[MODE]
upload_url = '%s://%s/%s' % (CONF[MODE]['htmethod'],
CONF[MODE]['host'],
path)
hmac_body = '%s\n%s\n/%s' % ("GET", expires, path)
signature = hmac.new(CONF[MODE]['account_formdata_key'],
hmac_body, sha1).hexdigest()
full_url = "%s?temp_url_sig=%s&temp_url_expires=%s&filename=attached.txt" % (
upload_url, signature, expires)
r = requests.get(full_url)
print r.headers['content-disposition']
@gholt
Copy link

gholt commented Mar 1, 2013

What was the output you got you didn't like?

@gholt
Copy link

gholt commented Mar 1, 2013

My reading comprehension failed. Ignore me. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment