aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/decorators.py24
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",