Created
July 12, 2016 16:17
-
-
Save cschwede/b61ac32b73ab4ac7314d761b54a099cf to your computer and use it in GitHub Desktop.
swift3_example_get.py
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
# 1. Created a simple object and uploaded it: | |
# echo "hello world" > obj | |
# swift upload cont obj | |
# 2. Get the S3 endpoint: | |
# openstack endpoint list | |
# use the ID for the s3 entry in the next command | |
# openstack endpoint show b7eee8134bc747af8aee553c94334ebc | |
# 3. Create EC creds: | |
# openstack ec2 credentials create | |
# you need access and secret | |
import base64, hashlib, hmac, time | |
from urllib import urlencode, quote_plus | |
from datetime import datetime, timedelta | |
base_url = 'http://10.0.2.15:8080' | |
path = '/cont/obj' | |
access = '0fb30cd628ff406592b8363d909a8465' | |
secret = '5db56362698e4316aac9cf7bcfe989bf' | |
expires = (datetime.utcnow() + timedelta(hours=1000)).strftime("%s") | |
string_to_sign = "GET\n\n\n%s\n%s" % (expires, path) | |
signature = hmac.new(key=secret, msg=string_to_sign, digestmod=hashlib.sha1).digest() | |
signature = base64.encodestring(signature).strip() | |
urlencoded_signature = quote_plus(signature) | |
url_string = "&Signature=%s" % urlencoded_signature | |
print "%s%s?AWSAccessKeyId=%s&Signature=%s&Expires=%s" % (base_url, path, access, urlencoded_signature, expires) | |
# Use curl and the given URL to access it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment