diff --git a/pyproject.toml b/pyproject.toml index f8da6ef..c6b4686 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "engineering@mediapredict.com"} diff --git a/resigner/utils.py b/resigner/utils.py index 7baf400..07a5ecd 100755 --- a/resigner/utils.py +++ b/resigner/utils.py @@ -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") @@ -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 \ No newline at end of file + return getattr(settings, name, default)