-
-
Save rcoup/8968765 to your computer and use it in GitHub Desktop.
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 base64 | |
import hashlib | |
import hmac | |
import time | |
from email.utils import formatdate | |
import requests | |
HOST="somewhere" | |
KEY_ID="gimme" | |
SECRET="ssshhh" | |
ACCEPT="something" | |
def gimme_yo_stuff(path): | |
time = formatdate(localtime=True) | |
requests.get(path, headers={ | |
"Accept": ACCEPT, | |
"Date": time, | |
"Authorization": "%s:%s" % (KEY_ID, signature_for_path(path, 'GET', time), | |
}) | |
def signature_for_path(path, method, time): | |
payload = string_to_sign(method, path, time) | |
h = hmac.new(SECRET, payload, hashlib.sha256) | |
d = h.digest() | |
return base64.b64encode(d) | |
def string_to_sign(method, path, time): | |
return "\n".join([method, HOST, path, time, KEY_ID, ACCEPT, '']) | |
# then call gimme_yo_stuff('/some/path')? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment