Commit e6884e39 authored by Kris Steinhoff's avatar Kris Steinhoff
Browse files

Use python-decouple

parent b9ff851b
Pipeline #17880 passed with stage
in 14 seconds
ADMINS=admin=admin-group@umich.edu
ADMINS=[["admin", "admin-group@umich.edu"]]
ALLOWED_HOSTS=127.0.0.1,localhost
DATABASE_URL=postgresql://postgres:passw0rd@db/postgres
DEBUG=1
......@@ -9,4 +9,4 @@ EMAIL_HOST=mail-relay.itd.umich.edu
EMAIL_SUBJECT_PREFIX=localhost
LOGGING_LEVEL=INFO
SECRET_KEY=123
SERVER_EMAIL=django@localhost
\ No newline at end of file
SERVER_EMAIL=django@localhost
......@@ -10,7 +10,10 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import json
import os
from decouple import config
import dj_database_url
......@@ -26,28 +29,26 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('SECRET_KEY')
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = str_to_bool(os.getenv('DEBUG', 'off'))
DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '127.0.0.1').split(',')
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')])
# https://docs.djangoproject.com/en/2.2/ref/settings/#admins
# e.g. ADMINS=admin=admin@umich.edu,user=user@umich.edu
# => [('admin', 'admin@umich.edu'), ('user', 'user@umich.edu')]
ADMINS = [tuple(a.split('=')) for a in os.getenv('ADMINS').split(',')] if os.getenv('ADMINS') else []
ADMINS = config('ADMINS', cast=json.loads)
# Email
# https://docs.djangoproject.com/en/3.0/topics/email/
if os.getenv('SERVER_EMAIL'):
SERVER_EMAIL = os.getenv('SERVER_EMAIL')
if config('SERVER_EMAIL'):
SERVER_EMAIL = config('SERVER_EMAIL')
EMAIL_HOST = os.getenv('EMAIL_HOST', None)
EMAIL_HOST = config('EMAIL_HOST', None)
EMAIL_SUBJECT_PREFIX = f'[{os.getenv("EMAIL_SUBJECT_PREFIX", "localhost")}] '
EMAIL_SUBJECT_PREFIX = f"[{config('EMAIL_SUBJECT_PREFIX', default='localhost')}] "
# Application definition
......@@ -112,22 +113,22 @@ AUTHENTICATION_BACKENDS = [
LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = os.getenv('LOGOUT_REDIRECT_URL', '/')
LOGOUT_REDIRECT_URL = config('LOGOUT_REDIRECT_URL', '/')
# Mozilla OIDC
# https://mozilla-django-oidc.readthedocs.io/en/stable/
OIDC_RP_CLIENT_ID = os.getenv('OIDC_RP_CLIENT_ID')
OIDC_RP_CLIENT_SECRET = os.getenv('OIDC_RP_CLIENT_SECRET')
OIDC_OP_AUTHORIZATION_ENDPOINT = os.getenv('OIDC_OP_AUTHORIZATION_ENDPOINT')
OIDC_OP_TOKEN_ENDPOINT = os.getenv('OIDC_OP_TOKEN_ENDPOINT')
OIDC_OP_USER_ENDPOINT = os.getenv('OIDC_OP_USER_ENDPOINT')
OIDC_RP_SIGN_ALGO = os.getenv('OIDC_RP_SIGN_ALGO', 'RS256')
OIDC_OP_JWKS_ENDPOINT = os.getenv('OIDC_OP_JWKS_ENDPOINT')
OIDC_RP_CLIENT_ID = config('OIDC_RP_CLIENT_ID')
OIDC_RP_CLIENT_SECRET = config('OIDC_RP_CLIENT_SECRET')
OIDC_OP_AUTHORIZATION_ENDPOINT = config('OIDC_OP_AUTHORIZATION_ENDPOINT')
OIDC_OP_TOKEN_ENDPOINT = config('OIDC_OP_TOKEN_ENDPOINT')
OIDC_OP_USER_ENDPOINT = config('OIDC_OP_USER_ENDPOINT')
OIDC_RP_SIGN_ALGO = config('OIDC_RP_SIGN_ALGO', 'RS256')
OIDC_OP_JWKS_ENDPOINT = config('OIDC_OP_JWKS_ENDPOINT')
OIDC_USERNAME_ALGO = 'oidc_auth.auth.generate_username'
OIDC_RP_SCOPES = 'openid email profile'
OIDC_CREATE_USER = str_to_bool(os.getenv('OIDC_CREATE_USER', 'on'))
OIDC_CREATE_USER = str_to_bool(config('OIDC_CREATE_USER', 'on'))
if (OIDC_RP_CLIENT_ID and OIDC_RP_CLIENT_SECRET and OIDC_OP_AUTHORIZATION_ENDPOINT
and OIDC_OP_TOKEN_ENDPOINT and OIDC_OP_USER_ENDPOINT):
......@@ -175,7 +176,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Detroit'
TIME_ZONE = config('TIME_ZONE', default='America/Detroit')
USE_I18N = True
......@@ -221,14 +222,14 @@ LOGGING = {
'loggers': {
**{
'django': {
'level': os.getenv('LOGGING_LEVEL', 'INFO'),
'level': config('LOGGING_LEVEL', default='INFO'),
'handlers': ['console', 'mail_admins'],
'propagate': True
},
},
**{
app: {
'level': os.getenv('LOGGING_LEVEL', 'INFO'),
'level': config('LOGGING_LEVEL', default='INFO'),
'handlers': ['console', 'mail_admins'],
'propagate': False
} for app in EXTRA_APPS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment