Skip to content

Instantly share code, notes, and snippets.

@jfilipe
Last active August 29, 2015 13:57
Show Gist options
  • Save jfilipe/9834103 to your computer and use it in GitHub Desktop.
Save jfilipe/9834103 to your computer and use it in GitHub Desktop.
Generate time based links for private bunches (nibbler.io).
import hmac
from hashlib import sha1
from time import time
NIBBLER_CUSTOMER_ID = 'xxx'
PRIVATE_BUNCH_NAME = 'xxx'
FILENAME = 'xxx'
LINK_EXPIRE_SECONDS = 60
NIBBLER_ACCESS_KEY = 'xxx'
expires = int(time() + LINK_EXPIRE_SECONDS)
path = "/v1/AUTH_{customer_id}/{bunch}/{filename}".format(
customer_id=NIBBLER_CUSTOMER_ID,
bunch=PRIVATE_BUNCH_NAME,
filename=FILENAME,
)
hmac_body = "GET\n{expires}\n{path}".format(
expires=expires,
path=path,
)
signature = hmac.new(NIBBLER_ACCESS_KEY, hmac_body, sha1).hexdigest()
url = "https://almond.nibbler.io{path}?Signature={signature}&Expires={expires}".format(
path=path,
signature=signature,
expires=expires,
)
print url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment