aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-15 13:44:33 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-15 13:44:33 +0000
commit7d6bec9cdb87b8ab31ad2c23b3d2d339595e5bb2 (patch)
treefcbc93c2f6bdc0433d540ddf978e9075961084be /pysite/base_route.py
parentFix odd typing error (diff)
Move API validation decorator to its own file #yxdk
Diffstat (limited to 'pysite/base_route.py')
-rw-r--r--pysite/base_route.py17
1 files changed, 1 insertions, 16 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
index 730b3e10..e1b9c6b2 100644
--- a/pysite/base_route.py
+++ b/pysite/base_route.py
@@ -2,9 +2,8 @@
import os
import random
import string
-from functools import wraps
-from flask import Blueprint, g, jsonify, render_template, request
+from flask import Blueprint, g, jsonify, render_template
from flask.views import MethodView
from rethinkdb.ast import Table
@@ -93,20 +92,6 @@ class APIView(RouteView):
pool = random.choices(string.ascii_letters + string.digits, k=32)
return "".join(pool)
- def valid_api_key(f):
- """
- Decorator to check if X-API-Key is valid.
- """
- @wraps(f)
- def has_valid_api_key(*args, **kwargs):
- if not request.headers.get("X-API-Key") == os.environ.get("API_KEY"):
- resp = jsonify({"error_code": 401, "error_message": "Invalid API-Key"})
- resp.status_code = 401
- return resp
- return f(*args, **kwargs)
-
- return has_valid_api_key
-
def error(self, error_code: ErrorCodes):
data = {