Skip to content

Instantly share code, notes, and snippets.

@rcoup
Forked from NZKoz/companies.rb
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcoup/8968765 to your computer and use it in GitHub Desktop.
Save rcoup/8968765 to your computer and use it in GitHub Desktop.
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