Skip to content

Instantly share code, notes, and snippets.

@thurloat
Last active November 11, 2017 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thurloat/b7bdbeff25213c87ebb7 to your computer and use it in GitHub Desktop.
Save thurloat/b7bdbeff25213c87ebb7 to your computer and use it in GitHub Desktop.
BulkStorage API Examples
import hmac
from hashlib import sha1
from time import time
method = 'GET'
duration_in_seconds = 60*60*24
expires = int(time() + duration_in_seconds)
path = '/v1/AUTH_{{ tenant_id }}/my_container/my_object'
key = 'qwertyuiopoiuytrewq'
s = 'https://{host}:8443/{path}?temp_url_sig={sig}&temp_url_expires={expires}'
hmac_body = '%s\n%s\n%s' % (method, expires, path)
sig = hmac.new(key.encode(), hmac_body.encode(), sha1).hexdigest()
url = s.format(host='swift.ca-ns-1.clouda.ca', path=path, sig=sig, expires=expires)
print(url)
# add a key to your account, so you can generate temp urls
swift post -m Temp-Url-Key:qwertyuiopoiuytrewq
# set a container world readable if you want (must be readable to use static site & listing features)
swift post -r ".r:*" my_container
# set an index file for static site hosting
swift post -m 'web-index:index.html' my_container
# or enable file listing
swift post -m 'web-listings: true' my_container
# set CORS headers on objects (CORS headers can only be set on objects, not containers)
swift post -m Access-Control-Allow-Origin:https://mysite.com my_container my_object
swift post -m Access-Control-Allow-Methods:GET my_container my_object
@thurloat
Copy link
Author

updated generate_temp_url.py:13 so it works with Python 3.x

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