feat: Use loadcredential package and rework settings

This commit is contained in:
Tom Hubrecht 2024-05-12 13:52:03 +02:00
parent 0b2d4523fe
commit 5d2342b7c6
6 changed files with 77 additions and 52 deletions

1
.credentials/SECRET_KEY Normal file
View file

@ -0,0 +1 @@
insecure-secret

View file

@ -42,6 +42,10 @@ in
env = {
DJANGO_SETTINGS_MODULE = "gestiojeux.settings";
CREDENTIALS_DIRECTORY = builtins.toString ./.credentials;
GESTIOJEUX_DEBUG = builtins.toJSON true;
};
};
}

View file

@ -1 +0,0 @@
settings.py

View file

@ -12,12 +12,67 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
import os
from loadcredential import Credentials
# Secrets
credentials = Credentials(env_prefix="GESTIOJEUX_")
SECRET_KEY = credentials["SECRET_KEY"]
DEBUG = credentials.get_json(
"DEBUG", False
) # SECURITY WARNING: don't run with debug turned on in production!
ALLOWED_HOSTS = credentials.get_json("ALLOWED_HOSTS", [])
ADMINS = credentials.get_json("ADMINS", [])
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PUBLIC_DIR = os.path.join(BASE_DIR, "public")
# Application definition
# Conditional settings
if DEBUG:
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
# Email
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
else:
EMAIL_HOST = "clipper.ens.fr"
SERVER_EMAIL = credentials["SERVER_EMAIL"]
DEFAULT_FROM_EMAIL = credentials["DEFAULT_FROM_EMAIL"]
# HTTPS only
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": credentials["DB_NAME"],
"USER": credentials["DB_USER"],
}
}
# Search engine
# https://django-haystack.readthedocs.io/en/latest/tutorial.html#configuration
HAYSTACK_CONNECTIONS = {
"default": {
"ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
"PATH": os.path.join(BASE_DIR, "whoosh_index"),
},
}
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
@ -111,12 +166,27 @@ MARKDOWNX_UPLOAD_MAX_SIZE = 1024 * 1024 # Only 1 MiB for markdown uploads
# Update the search database on save
HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = "fr"
TIME_ZONE = "Europe/Paris"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = "/static/"
MEDIA_URL = "/media/"
# Directories
STATIC_ROOT = os.path.join(PUBLIC_DIR, "static")
MEDIA_ROOT = os.path.join(PUBLIC_DIR, "media")
# CAS settings
CAS_SERVER_URL = "https://cas.eleves.ens.fr/"
CAS_VERIFY_URL = "https://cas.eleves.ens.fr/"
CAS_VERSION = "CAS_2_SAML_1_0"

View file

@ -1,50 +0,0 @@
"""
Django settings for jeulee project dev base settings
"""
import os
from .settings_base import *
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "CHANGE_ME" # FIXME
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
# Search engine
# https://django-haystack.readthedocs.io/en/latest/tutorial.html#configuration
HAYSTACK_CONNECTIONS = {
"default": {
"ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
"PATH": os.path.join(BASE_DIR, "whoosh_index"),
},
}
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = "fr"
TIME_ZONE = "Europe/Paris"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Directories
STATIC_ROOT = os.path.join(PUBLIC_DIR, "static")
MEDIA_ROOT = os.path.join(PUBLIC_DIR, "media")
# Email
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

View file

@ -8,3 +8,4 @@ django-tables2==2.7.0
markdown-iconfonts==3.0.0
Pillow==10.1.0
Whoosh==2.7.4
loadcredential==1.1