IdHub/trustchain_idhub/settings.py

247 lines
7.0 KiB
Python
Raw Permalink Normal View History

"""
Django settings for trustchain_idhub project.
Generated by 'django-admin startproject' using Django 4.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
2023-10-18 09:35:08 +00:00
import os
from ast import literal_eval
2023-12-12 12:22:43 +00:00
from dj_database_url import parse as db_url
from pathlib import Path
2023-10-13 19:04:44 +00:00
from django.contrib.messages import constants as messages
2023-10-18 09:25:12 +00:00
from decouple import config, Csv
2023-10-13 19:04:44 +00:00
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
2023-10-18 09:25:12 +00:00
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
2023-10-18 09:25:12 +00:00
DEBUG = config('DEBUG', default=False, cast=bool)
DOMAIN = config("DOMAIN")
assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY"
2024-03-06 17:23:27 +00:00
# this var is very important, we print it
print("DOMAIN: " + DOMAIN)
2023-10-18 09:25:12 +00:00
2024-03-04 08:44:53 +00:00
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv())
assert DOMAIN in ALLOWED_HOSTS, "DOMAIN is not ALLOWED_HOST"
CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default=f'https://{DOMAIN}', cast=Csv())
INITIAL_ADMIN_EMAIL = config("INITIAL_ADMIN_EMAIL", default='admin@example.org')
INITIAL_ADMIN_PASSWORD = config("INITIAL_ADMIN_PASSWORD", default='1234')
2023-10-18 09:25:12 +00:00
DEFAULT_FROM_EMAIL = config(
'DEFAULT_FROM_EMAIL', default='webmaster@localhost')
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)
EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)
EMAIL_BACKEND = config('EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
EMAIL_FILE_PATH = config('EMAIL_FILE_PATH', default='/tmp/app-messages')
ADMINS = config('ADMINS', default='[]', cast=literal_eval)
MANAGERS = config('MANAGERS', default='[]', cast=literal_eval)
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
2023-09-29 16:06:17 +00:00
'django_extensions',
2023-10-11 07:52:05 +00:00
'django_bootstrap5',
'django_tables2',
2023-10-25 15:49:17 +00:00
'idhub_auth',
2023-11-24 15:36:05 +00:00
'oidc4vp',
2023-12-04 16:12:39 +00:00
'idhub',
'promotion',
'webhook'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
2023-11-28 09:17:59 +00:00
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'trustchain_idhub.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'trustchain_idhub.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
2023-12-12 12:22:43 +00:00
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
'default': config(
'DATABASE_URL',
default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'),
cast=db_url
)
2023-10-18 09:25:12 +00:00
# 'default': config(
# 'DATABASE_URL',
# default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3'),
# cast=db_url
# )
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
2024-01-06 18:18:59 +00:00
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
2023-10-18 09:25:12 +00:00
TIME_ZONE = config('TIME_ZONE', 'UTC')
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
2023-10-18 09:25:12 +00:00
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = config('STATIC_ROOT')
MEDIA_ROOT = config('MEDIA_ROOT', default="idhub/upload")
FIXTURE_DIRS = (os.path.join(BASE_DIR, 'fixtures'),)
2023-10-20 14:50:53 +00:00
SCHEMAS_DIR = os.path.join(BASE_DIR, 'schemas')
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
2023-10-18 09:25:12 +00:00
LOGIN_REDIRECT_URL = 'idhub:user_dashboard'
2023-10-09 08:55:50 +00:00
LOGOUT_REDIRECT_URL = 'idhub:login'
2023-10-13 19:04:44 +00:00
MESSAGE_TAGS = {
messages.DEBUG: 'alert-secondary',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
2023-10-18 15:30:11 +00:00
2023-11-08 10:23:53 +00:00
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
2024-03-19 09:58:17 +00:00
# LANGUAGE_CODE="en"
2023-11-22 12:59:09 +00:00
# LANGUAGE_CODE="es"
2024-03-20 15:52:05 +00:00
LANGUAGE_CODE = config('LANGUAGE_CODE', "en")
2023-12-14 11:13:58 +00:00
gettext = lambda s: s
LANGUAGES = (
('de', gettext('German')),
('en', gettext('English')),
('ca', gettext('Catalan')),
2024-03-19 09:58:17 +00:00
('es', gettext('Spanish')),
2023-12-14 11:13:58 +00:00
)
2023-11-10 15:22:41 +00:00
USE_I18N = True
USE_L10N = True
2023-11-08 10:23:53 +00:00
2023-10-25 15:49:17 +00:00
AUTH_USER_MODEL = 'idhub_auth.User'
2024-03-04 08:44:53 +00:00
2024-03-04 09:30:42 +00:00
OIDC_REDIRECT = config('OIDC_REDIRECT', default=False, cast=bool)
ALLOW_CODE_URI = config(
2024-03-04 08:44:53 +00:00
'ALLOW_CODE_URI',
default=f"https://{DOMAIN}/oidc4vp/allow_code"
2024-03-04 08:44:53 +00:00
)
2023-11-29 11:06:53 +00:00
SUPPORTED_CREDENTIALS = config(
'SUPPORTED_CREDENTIALS',
default='[]',
cast=literal_eval
)
2023-12-15 13:08:03 +00:00
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
2024-02-22 12:47:58 +00:00
"console": {"level": "DEBUG", "class": "logging.StreamHandler"},
2023-12-15 13:08:03 +00:00
},
2024-02-22 12:47:58 +00:00
"root": {
"handlers": ["console"],
"level": "DEBUG",
2023-12-15 13:08:03 +00:00
}
}
SYNC_ORG_DEV = config('SYNC_ORG_DEV', 'y')
2024-03-05 09:56:41 +00:00
OIDC_ORGS = config('OIDC_ORGS', '')
ENABLE_EMAIL = config('ENABLE_EMAIL', default=True, cast=bool)
CREATE_TEST_USERS = config('CREATE_TEST_USERS', default=False, cast=bool)
ENABLE_2FACTOR_AUTH = config('ENABLE_2FACTOR_AUTH', default=True, cast=bool)
2024-02-20 18:20:49 +00:00
COMMIT = config('COMMIT', default='')
2024-06-17 09:07:51 +00:00
API_TOKEN = config("API_TOKEN", '')
VERIFIABLE_REGISTER_URL = config("VERIFIABLE_REGISTER_URL")
RESTRICTED_ISSUANCE_CREDENTIAL_TYPES = config('RESTRICTED_ISSUANCE_CREDENTIAL_TYPES', default=[], cast=literal_eval)