summaryrefslogtreecommitdiffstats
path: root/takahe
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-12 22:10:06 -0700
committerAndrew Godwin2022-11-12 22:10:06 -0700
commit143a4a6e8c70557710d1b207a176f169d145ed1e (patch)
tree133454aa4da2b5614a33bc4a91d7b152f50eb40c /takahe
parent878f56b411279cd9865a7ec05f1d14c9f70f6187 (diff)
downloadtakahe-143a4a6e8c70557710d1b207a176f169d145ed1e.tar.gz
takahe-143a4a6e8c70557710d1b207a176f169d145ed1e.tar.bz2
takahe-143a4a6e8c70557710d1b207a176f169d145ed1e.zip
Start some settings work
Diffstat (limited to 'takahe')
-rw-r--r--takahe/asgi.py2
-rw-r--r--takahe/settings/__init__.py0
-rw-r--r--takahe/settings/base.py (renamed from takahe/settings.py)20
-rw-r--r--takahe/settings/development.py13
-rw-r--r--takahe/settings/production.py17
-rw-r--r--takahe/settings/testing.py4
-rw-r--r--takahe/wsgi.py2
7 files changed, 38 insertions, 20 deletions
diff --git a/takahe/asgi.py b/takahe/asgi.py
index 99a9cfb..3424b23 100644
--- a/takahe/asgi.py
+++ b/takahe/asgi.py
@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings.production")
application = get_asgi_application()
diff --git a/takahe/settings/__init__.py b/takahe/settings/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/takahe/settings/__init__.py
diff --git a/takahe/settings.py b/takahe/settings/base.py
index e8982ae..a2ccb98 100644
--- a/takahe/settings.py
+++ b/takahe/settings/base.py
@@ -1,17 +1,7 @@
import os
from pathlib import Path
-# Build paths inside the project like this: BASE_DIR / 'subdir'.
-BASE_DIR = Path(__file__).resolve().parent.parent
-
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = os.environ.get("SECRET_KEY", "insecure_secret")
-
-# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = True
-
-ALLOWED_HOSTS = ["*"]
-CSRF_TRUSTED_ORIGINS = ["http://*", "https://*"]
+BASE_DIR = Path(__file__).resolve().parent.parent.parent
# Application definition
@@ -30,7 +20,6 @@ INSTALLED_APPS = [
]
MIDDLEWARE = [
- "core.middleware.AlwaysSecureMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
@@ -115,9 +104,4 @@ STATICFILES_DIRS = [
BASE_DIR / "static",
]
-CRISPY_FAIL_SILENTLY = not DEBUG
-
-SITE_NAME = "takahē"
-DEFAULT_DOMAIN = "feditest.aeracode.org"
-ALLOWED_DOMAINS = ["feditest.aeracode.org"]
-IDENTITY_MAX_AGE = 24 * 60 * 60
+ALLOWED_HOSTS = ["*"]
diff --git a/takahe/settings/development.py b/takahe/settings/development.py
new file mode 100644
index 0000000..4e0098b
--- /dev/null
+++ b/takahe/settings/development.py
@@ -0,0 +1,13 @@
+import os
+
+from .base import * # noqa
+
+# Load secret key from environment with a fallback
+SECRET_KEY = os.environ.get("TAKAHE_SECRET_KEY", "insecure_secret")
+
+# Disable the CRSF origin protection
+MIDDLEWARE.insert(0, "core.middleware.AlwaysSecureMiddleware")
+
+# Ensure debug features are on
+DEBUG = True
+CRISPY_FAIL_SILENTLY = False
diff --git a/takahe/settings/production.py b/takahe/settings/production.py
new file mode 100644
index 0000000..2f943f4
--- /dev/null
+++ b/takahe/settings/production.py
@@ -0,0 +1,17 @@
+import os
+
+from .base import * # noqa
+
+# Load secret key from environment
+try:
+ SECRET_KEY = os.environ["TAKAHE_SECRET_KEY"]
+except KeyError:
+ print("You must specify the TAKAHE_SECRET_KEY environment variable!")
+ os._exit(1)
+
+# Ensure debug features are off
+DEBUG = False
+CRISPY_FAIL_SILENTLY = True
+
+# TODO: Allow better setting of allowed_hosts, if we need to
+ALLOWED_HOSTS = ["*"]
diff --git a/takahe/settings/testing.py b/takahe/settings/testing.py
new file mode 100644
index 0000000..6527333
--- /dev/null
+++ b/takahe/settings/testing.py
@@ -0,0 +1,4 @@
+from .base import * # noqa
+
+# Fixed secret key
+SECRET_KEY = "testing_secret"
diff --git a/takahe/wsgi.py b/takahe/wsgi.py
index 05ae06f..c8ad0a0 100644
--- a/takahe/wsgi.py
+++ b/takahe/wsgi.py
@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "takahe.settings.production")
application = get_wsgi_application()