Last active
November 11, 2017 02:24
-
-
Save thurloat/b7bdbeff25213c87ebb7 to your computer and use it in GitHub Desktop.
BulkStorage API Examples
This file contains hidden or 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
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) |
This file contains hidden or 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
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated generate_temp_url.py:13 so it works with Python 3.x