Created
November 13, 2012 18:39
-
-
Save DmZ/4067564 to your computer and use it in GitHub Desktop.
Simple S3 signing for expiring URLs
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
#!/usr/bin/env python | |
import os | |
import sys | |
import hmac | |
import time | |
import urllib | |
import base64 | |
import hashlib | |
import urlparse | |
expires = int(time.time() + int(sys.argv[1])) | |
url = urlparse.urlparse(sys.argv[2]) | |
access_key = os.environ["AWS_ACCESS_KEY_ID"] | |
secret_key = os.environ["AWS_SECRET_ACCESS_KEY"] | |
h = hmac.new(secret_key, | |
"GET\n\n\n%d\n%s" % (expires, url.path), | |
hashlib.sha1) | |
sign = urllib.quote_plus(base64.encodestring(h.digest()).strip()) | |
print("%s?AWSAccessKeyId=%s&Expires=%d&Signature=%s" % (sys.argv[2], | |
access_key, | |
expires, sign)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment