Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback_keys arg to Signer. Cleanup. #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "resigner"
version = "0.3.12"
version = "0.3.13"
authors = [
{name = "Media Predict"},
{email = "[email protected]"}
Expand Down
23 changes: 15 additions & 8 deletions resigner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

HEADER_KEY_PREFIX = "RESIGNER"

add_prefix = lambda key : "{0}{1}{2}".format(HEADER_KEY_PREFIX, "-", key)
to_server_key = lambda key : "{0}{1}{2}".format("HTTP", "-", key).replace("-", "_")

def add_prefix(key):
return f"{HEADER_KEY_PREFIX}-{key}"


def to_server_key(key):
return f"HTTP_{key}".replace("-", "_")


CLIENT_TIME_STAMP_KEY = add_prefix("TIME-STAMP")
CLIENT_API_SIGNATURE_KEY = add_prefix("API-SIGNATURE")
Expand All @@ -14,15 +20,16 @@
SERVER_API_SIGNATURE_KEY = to_server_key(CLIENT_API_SIGNATURE_KEY)
SERVER_API_KEY = to_server_key(CLIENT_API_KEY)


def get_signature(secret, body, timestamp, url):
if not body:
body = ""

signer = Signer(key=secret)
return signer.signature( ":".join([body, timestamp, url]) )
# fallback_keys="" prevents fetching from django config
# Our Analytics package is meant for use outside of django
signer = Signer(key=secret, fallback_keys="")
return signer.signature(f"{body}:{timestamp}:{url}")


def get_settings_param(name, default=0):
if hasattr(settings, name):
return getattr(settings, name)
else:
return default
return getattr(settings, name, default)
Loading