Jan Dittberner
34f788e099
This commit reorganizes the package structure. The gvaldap.settings modules have been merged. The gvaldap.ldaptasks module has been move up one level to have task names without the gvaldap prefix. isort control instructions have been added to setup.cfg.
316 lines
9.8 KiB
Python
316 lines
9.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# pymode:lint_ignore=E501
|
|
"""
|
|
Common settings and globals.
|
|
|
|
"""
|
|
|
|
from os.path import abspath, basename, dirname, join, normpath
|
|
from sys import path
|
|
|
|
from gvacommon.settings_utils import get_env_variable
|
|
|
|
# ######### PATH CONFIGURATION
|
|
# Absolute filesystem path to the Django project directory:
|
|
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
|
|
|
|
# Absolute filesystem path to the top-level project folder:
|
|
SITE_ROOT = dirname(DJANGO_ROOT)
|
|
|
|
# Site name:
|
|
SITE_NAME = basename(DJANGO_ROOT)
|
|
|
|
# Add our project to our pythonpath, this way we don't need to type our project
|
|
# name in our dotted import paths:
|
|
path.append(DJANGO_ROOT)
|
|
# ######### END PATH CONFIGURATION
|
|
|
|
|
|
# ######### DEBUG CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
|
DEBUG = get_env_variable("GVALDAP_DEBUG", bool, False)
|
|
|
|
# ######### MANAGER CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
|
ADMINS = (
|
|
(get_env_variable("GVALDAP_ADMIN_NAME"), get_env_variable("GVALDAP_ADMIN_EMAIL")),
|
|
)
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
|
MANAGERS = ADMINS
|
|
# ######### END MANAGER CONFIGURATION
|
|
|
|
|
|
# ######### DATABASE CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": normpath(join(DJANGO_ROOT, "default.db")),
|
|
"USER": "",
|
|
"PASSWORD": "",
|
|
"HOST": "",
|
|
"PORT": "",
|
|
},
|
|
"ldap": {
|
|
"ENGINE": "ldapdb.backends.ldap",
|
|
"NAME": get_env_variable("GVALDAP_LDAP_URL"),
|
|
"USER": get_env_variable("GVALDAP_LDAP_USER"),
|
|
"PASSWORD": get_env_variable("GVALDAP_LDAP_PASSWORD"),
|
|
},
|
|
}
|
|
DATABASE_ROUTERS = ["ldapdb.router.Router"]
|
|
# ######### END DATABASE CONFIGURATION
|
|
|
|
|
|
# ######### GENERAL CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
|
|
TIME_ZONE = "Europe/Berlin"
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
|
|
LANGUAGE_CODE = "en-us"
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
|
|
SITE_ID = 1
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
|
|
USE_I18N = True
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
|
|
USE_L10N = True
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
|
|
USE_TZ = True
|
|
# ######### END GENERAL CONFIGURATION
|
|
|
|
|
|
# ######### MEDIA CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
|
|
MEDIA_ROOT = normpath(join(SITE_ROOT, "media"))
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
|
|
MEDIA_URL = "/media/"
|
|
# ######### END MEDIA CONFIGURATION
|
|
|
|
|
|
# ######### STATIC FILE CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
|
|
STATIC_URL = "/static/"
|
|
|
|
# See:
|
|
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders # noqa
|
|
STATICFILES_FINDERS = ("django.contrib.staticfiles.finders.AppDirectoriesFinder",)
|
|
# ######### END STATIC FILE CONFIGURATION
|
|
|
|
|
|
# ######### SECRET CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
|
# Note: This key should only be used for development and testing.
|
|
SECRET_KEY = get_env_variable("GVALDAP_SECRETKEY")
|
|
# ######### END SECRET CONFIGURATION
|
|
|
|
|
|
# ######### FIXTURE CONFIGURATION
|
|
# See:
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS # noqa
|
|
FIXTURE_DIRS = (normpath(join(SITE_ROOT, "fixtures")),)
|
|
# ######### END FIXTURE CONFIGURATION
|
|
|
|
|
|
# ######### TEMPLATE CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-TEMPLATES # noqa
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [normpath(join(SITE_ROOT, "templates"))],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.template.context_processors.debug",
|
|
"django.template.context_processors.i18n",
|
|
"django.template.context_processors.media",
|
|
"django.template.context_processors.static",
|
|
"django.template.context_processors.tz",
|
|
"django.contrib.messages.context_processors.messages",
|
|
"django.template.context_processors.request",
|
|
]
|
|
},
|
|
}
|
|
]
|
|
|
|
# ######### END TEMPLATE CONFIGURATION
|
|
|
|
|
|
# ######### MIDDLEWARE CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes
|
|
MIDDLEWARE = (
|
|
# Default Django middleware.
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
)
|
|
# ######### END MIDDLEWARE CONFIGURATION
|
|
|
|
|
|
# ######### URL CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
|
|
ROOT_URLCONF = "%s.urls" % SITE_NAME
|
|
# ######### END URL CONFIGURATION
|
|
|
|
|
|
# ######### TEST RUNNER CONFIGURATION
|
|
TEST_RUNNER = "django.test.runner.DiscoverRunner"
|
|
# ######### END TEST RUNNER CONFIGURATION
|
|
|
|
|
|
# ######### APP CONFIGURATION
|
|
DJANGO_APPS = (
|
|
# Default Django apps:
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.sites",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
# Admin panel and documentation:
|
|
"django.contrib.admin",
|
|
)
|
|
|
|
# Apps specific for this project go here.
|
|
LOCAL_APPS = ("ldapentities", "ldaptasks")
|
|
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
|
INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS
|
|
# ######### END APP CONFIGURATION
|
|
|
|
|
|
# ######### LOGGING CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
|
# A sample logging configuration. The only tangible logging
|
|
# performed by this configuration is to send an email to
|
|
# the site admins on every HTTP 500 error when DEBUG=False.
|
|
# See http://docs.djangoproject.com/en/dev/topics/logging for
|
|
# more details on how to customize your logging configuration.
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"verbose": {
|
|
"format": "%(levelname)s %(asctime)s %(name)s "
|
|
"%(module)s:%(lineno)d %(process)d %(thread)d %(message)s"
|
|
},
|
|
"simple": {"format": "%(levelname)s %(name)s:%(lineno)d %(message)s"},
|
|
},
|
|
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
|
|
"handlers": {
|
|
"mail_admins": {
|
|
"level": "ERROR",
|
|
"filters": ["require_debug_false"],
|
|
"class": "django.utils.log.AdminEmailHandler",
|
|
}
|
|
},
|
|
"loggers": {
|
|
"django.request": {
|
|
"handlers": ["mail_admins"],
|
|
"level": "ERROR",
|
|
"propagate": True,
|
|
}
|
|
},
|
|
}
|
|
# ######### END LOGGING CONFIGURATION
|
|
|
|
|
|
# ######### WSGI CONFIGURATION
|
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
|
|
WSGI_APPLICATION = "%s.wsgi.application" % SITE_NAME
|
|
# ######### END WSGI CONFIGURATION
|
|
|
|
|
|
# ######### LDAP SETTINGS
|
|
GROUP_BASE_DN = get_env_variable("GVALDAP_BASEDN_GROUP")
|
|
USER_BASE_DN = get_env_variable("GVALDAP_BASEDN_USER")
|
|
# ######### END LDAP SETTINGS
|
|
|
|
|
|
# ######### CELERY CONFIGURATION
|
|
CELERY_BROKER_URL = get_env_variable("GVALDAP_BROKER_URL")
|
|
CELERY_RESULT_BACKEND = get_env_variable("GVALDAP_RESULTS_REDIS_URL")
|
|
CELERY_TASK_RESULT_EXPIRES = None
|
|
CELERY_ROUTES = ("gvacommon.celeryrouters.GvaRouter",)
|
|
CELERY_TIMEZONE = "Europe/Berlin"
|
|
CELERY_ENABLE_UTC = True
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
CELERY_TASK_SERIALIZER = "json"
|
|
CELERY_RESULT_SERIALIZER = "json"
|
|
# ######### END CELERY CONFIGURATION
|
|
|
|
if DEBUG:
|
|
TEMPLATES[0]["OPTIONS"]["debug"] = DEBUG
|
|
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
|
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
|
|
INSTALLED_APPS += ("debug_toolbar",)
|
|
|
|
MIDDLEWARE += ("debug_toolbar.middleware.DebugToolbarMiddleware",)
|
|
|
|
LOGGING["handlers"].update(
|
|
{
|
|
"console": {
|
|
"level": "DEBUG",
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "simple",
|
|
}
|
|
}
|
|
)
|
|
LOGGING["loggers"].update(
|
|
dict(
|
|
[
|
|
(key, {"handlers": ["console"], "level": "DEBUG", "propagate": True})
|
|
for key in ["ldapentities", "ldaptasks"]
|
|
]
|
|
)
|
|
)
|
|
INTERNAL_IPS = get_env_variable("GVALDAP_INTERNAL_IPS", str, "127.0.0.1").split(",")
|
|
else:
|
|
ALLOWED_HOSTS = get_env_variable("GVALDAP_ALLOWED_HOSTS").split(",")
|
|
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
|
EMAIL_SUBJECT_PREFIX = "[%s] " % SITE_NAME
|
|
DEFAULT_FROM_EMAIL = get_env_variable("GVALDAP_ADMIN_EMAIL")
|
|
SERVER_EMAIL = get_env_variable("GVALDAP_SERVER_EMAIL")
|
|
|
|
if get_env_variable("GVALDAP_TEST", bool, False):
|
|
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)
|
|
# ######### IN-MEMORY TEST DATABASE
|
|
DATABASES["default"] = {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": ":memory:",
|
|
"USER": "",
|
|
"PASSWORD": "",
|
|
"HOST": "",
|
|
"PORT": "",
|
|
}
|
|
|
|
LOGGING["handlers"].update(
|
|
{
|
|
"console": {
|
|
"level": "ERROR",
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "simple",
|
|
}
|
|
}
|
|
)
|
|
LOGGING["loggers"].update(
|
|
dict(
|
|
[
|
|
(key, {"handlers": ["console"], "level": "ERROR", "propagate": True})
|
|
for key in ["ldapentities", "ldaptasks"]
|
|
]
|
|
)
|
|
)
|
|
CELERY_BROKER_URL = CELERY_BROKER_URL + "_test"
|
|
CELERY_RESULT_PERSISTENT = False
|