diff options
author | BonfaceKilz | 2021-10-15 15:47:21 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-10-25 14:00:14 +0300 |
commit | 8dd3457b20b5ce96cf7e0f5029e3541d57ca116d (patch) | |
tree | c377b89bed5fe26d1f3d729afc45df4544df3d57 | |
parent | da86bc79798c05ec469d76f375741f306213e4d0 (diff) | |
download | genenetwork2-8dd3457b20b5ce96cf7e0f5029e3541d57ca116d.tar.gz |
Remove "utility.hmac.hmac_creation" which causes circular imports
Hacky but re-implement `hmac_creation` as `create_hmac`
-rw-r--r-- | wqflask/wqflask/decorators.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/wqflask/wqflask/decorators.py b/wqflask/wqflask/decorators.py index c19e1aef..5930e7ec 100644 --- a/wqflask/wqflask/decorators.py +++ b/wqflask/wqflask/decorators.py @@ -1,26 +1,34 @@ """This module contains gn2 decorators""" -from flask import g +import hashlib +import hmac +from flask import current_app, g from typing import Dict from functools import wraps -from utility.hmac import hmac_creation -from utility.tools import GN_PROXY_URL import json import requests +def create_hmac(data: str, secret: str) -> str: + return hmac.new(bytearray(secret, "latin-1"), + bytearray(data, "utf-8"), + hashlib.sha1).hexdigest[:20] def edit_access_required(f): """Use this for endpoints where admins are required""" @wraps(f) def wrap(*args, **kwargs): resource_id: str = "" if kwargs.get("inbredset_id"): # data type: dataset-publish - resource_id = hmac_creation("dataset-publish:" - f"{kwargs.get('inbredset_id')}:" - f"{kwargs.get('name')}") + resource_id = create_hmac( + data=("dataset-publish:" + f"{kwargs.get('inbredset_id')}:" + f"{kwargs.get('name')}"), + secret=current_app.config.get("SECRET_HMAC_CODE")) if kwargs.get("dataset_name"): # data type: dataset-probe - resource_id = hmac_creation("dataset-probeset:" - f"{kwargs.get('dataset_name')}") + resource_id = create_hmac( + data=("dataset-probeset:" + f"{kwargs.get('dataset_name')}"), + secret=current_app.config.get("SECRET_HMAC_CODE")) response: Dict = {} try: _user_id = g.user_session.record.get(b"user_id", |