From bfbaab2e029f05b63fcd12a7464a3c96eed25907 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 7 May 2021 15:05:31 +0200 Subject: [PATCH] auth and limit --- Auth.py | 4 ++-- Entries.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Auth.py b/Auth.py index 5fbf66a..4db5495 100644 --- a/Auth.py +++ b/Auth.py @@ -3,11 +3,11 @@ import os import werkzeug -JWT_SECRET = os.environ['JWT_SECRET'] +JWT_PUB_KEY = os.environ['JWT_PUB_KEY'] def decodeToken(token): try: - return jwt.decode(token, JWT_SECRET) + return jwt.decode(token, JWT_PUB_KEY, audience="mainscnt") except JWTError as e: print("ERROR: decodeToken: {}".format(e)) raise werkzeug.exceptions.Unauthorized() diff --git a/Entries.py b/Entries.py index aa6f253..2498bc0 100644 --- a/Entries.py +++ b/Entries.py @@ -25,12 +25,18 @@ def insert(**args): def get(start, stop, token_info=None, location=None): + logging.info("Token: {}".format(token_info)) if 'read/mainscnt/entries' not in token_info['x-scope']: raise werkzeug.exceptions.Forbidden() + LIMITS_PREFIX = 'mainscnt/entries/' + limit = 0 + if ('x-limits' in token_info) and (token_info['x-limits'].startswith(LIMITS_PREFIX)): + limit = int(token_info['x-limits'][len(LIMITS_PREFIX):]) res = [ { 'timestamp': datetime.datetime.now(), - 'frequency': 50.0 + 'frequency': 50.0, + 'maxentries': limit } ] return res \ No newline at end of file