aboutsummaryrefslogtreecommitdiffstats
path: root/pysite
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-08 11:30:50 +0100
committerGravatar Gareth Coles <[email protected]>2018-05-08 11:30:50 +0100
commit81e32cbb1b9ae40283bcbaef606ef9e09cb71ae6 (patch)
tree07c57d7ae057073c4c586f77e267a0712f6e7833 /pysite
parent[Wiki] Fix an editor dumb: `not not` (diff)
Move bot API key to a constant
Diffstat (limited to 'pysite')
-rw-r--r--pysite/constants.py3
-rw-r--r--pysite/decorators.py5
2 files changed, 5 insertions, 3 deletions
diff --git a/pysite/constants.py b/pysite/constants.py
index 225550fe..49882030 100644
--- a/pysite/constants.py
+++ b/pysite/constants.py
@@ -82,3 +82,6 @@ GITHUB_TOKEN = environ.get("GITHUB_TOKEN") or None
# Audit Webhook
WIKI_AUDIT_WEBHOOK = environ.get("WIKI_AUDIT_WEBHOOK") or None
+
+# Bot key
+BOT_API_KEY = environ.get("BOT_API_KEY") or None
diff --git a/pysite/decorators.py b/pysite/decorators.py
index 0c31fe6e..befc0869 100644
--- a/pysite/decorators.py
+++ b/pysite/decorators.py
@@ -1,4 +1,3 @@
-import os
from functools import wraps
from json import JSONDecodeError
@@ -7,7 +6,7 @@ from schema import Schema, SchemaError
from werkzeug.exceptions import Forbidden
from pysite.base_route import APIView, BaseView
-from pysite.constants import CSRF, DEBUG_MODE, ErrorCodes, ValidationTypes
+from pysite.constants import CSRF, DEBUG_MODE, ErrorCodes, ValidationTypes, BOT_API_KEY
def csrf(f):
@@ -58,7 +57,7 @@ def api_key(f):
@wraps(f)
def inner_decorator(self: APIView, *args, **kwargs):
- if not request.headers.get("X-API-Key") == os.environ.get("BOT_API_KEY"):
+ if not request.headers.get("X-API-Key") == BOT_API_KEY:
return self.error(ErrorCodes.invalid_api_key)
return f(self, *args, **kwargs)