Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 4d0d21d3 authored by Kris Steinhoff's avatar Kris Steinhoff
Browse files

Merge branch 'decouple' into 'master'

Use python-decouple

See merge request !4
parents b9ff851b 78d6e3a4
Pipeline #17897 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,12 +10,11 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import json
import os
import dj_database_url
def str_to_bool(val):
return val.lower() in ('yes', 'true', 'on', '1')
from decouple import config
import dj_database_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
......@@ -26,28 +25,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 +109,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', default=None)
OIDC_RP_CLIENT_SECRET = config('OIDC_RP_CLIENT_SECRET', default=None)
OIDC_OP_AUTHORIZATION_ENDPOINT = config('OIDC_OP_AUTHORIZATION_ENDPOINT', default=None)
OIDC_OP_TOKEN_ENDPOINT = config('OIDC_OP_TOKEN_ENDPOINT', default=None)
OIDC_OP_USER_ENDPOINT = config('OIDC_OP_USER_ENDPOINT', default=None)
OIDC_RP_SIGN_ALGO = config('OIDC_RP_SIGN_ALGO', default='RS256')
OIDC_OP_JWKS_ENDPOINT = config('OIDC_OP_JWKS_ENDPOINT', default=None)
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 = config('OIDC_CREATE_USER', default=True, cast=bool)
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 +172,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 +218,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
......
asgiref==3.2.7
certifi==2019.11.28
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
cryptography==2.8
cryptography==2.9
dj-database-url==0.5.0
Django==3.0.4
Django==3.0.5
gunicorn==20.0.4
idna==2.9
josepy==1.3.0
mozilla-django-oidc==1.2.3
psycopg2==2.8.4
psycopg2==2.8.5
pycparser==2.20
pyOpenSSL==19.1.0
python-decouple==3.3
pytz==2019.3
requests==2.23.0
six==1.14.0
sqlparse==0.3.1
urllib3==1.25.8
whitenoise==5.0.1
whitenoise==5.0.1
\ No newline at end of file
......@@ -3,4 +3,5 @@ whitenoise~=5.0.1
gunicorn~=20.0.4
mozilla-django-oidc~=1.2.3
dj-database-url~=0.5.0
psycopg2~=2.8.4
\ No newline at end of file
psycopg2~=2.8.4
python-decouple~=3.3
\ No newline at end of file
Markdown is supported
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