Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mpicms/config/settings/production.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
169 lines (153 sloc)
6.03 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ldap | |
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType | |
from .base import * # noqa | |
from .base import env | |
# GENERAL | |
# ------------------------------------------------------------------------------ | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key | |
SECRET_KEY = env('DJANGO_SECRET_KEY') | |
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts | |
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['twiki.molgen.mpg.de']) | |
# DATABASES | |
# ------------------------------------------------------------------------------ | |
DATABASES['default'] = env.db('DATABASE_URL') # noqa F405 | |
DATABASES['default']['ATOMIC_REQUESTS'] = True # noqa F405 | |
DATABASES['default']['CONN_MAX_AGE'] = env.int('CONN_MAX_AGE', default=60) # noqa F405 | |
# CACHES | |
# ------------------------------------------------------------------------------ | |
CACHES = { | |
'default': { | |
'BACKEND': 'django_redis.cache.RedisCache', | |
'LOCATION': env('REDIS_URL'), | |
'OPTIONS': { | |
'CLIENT_CLASS': 'django_redis.client.DefaultClient', | |
# Mimicing memcache behavior. | |
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior | |
'IGNORE_EXCEPTIONS': True, | |
} | |
} | |
} | |
# AUTHENTICATION | |
AUTHENTICATION_BACKENDS = [ | |
'django_auth_ldap.backend.LDAPBackend', | |
# 'django.contrib.auth.backends.ModelBackend', | |
] | |
AUTH_LDAP_SERVER_URI = "ldap://127.0.0.1:10389/" | |
AUTH_LDAP_BIND_DN = "" | |
AUTH_LDAP_BIND_PASSWORD = "" | |
AUTH_LDAP_USER_SEARCH = LDAPSearch( | |
"ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)") | |
AUTH_LDAP_FIND_GROUP_PERMS = True | |
AUTH_LDAP_GROUP_SEARCH = LDAPSearch( | |
'ou=groups,dc=example,dc=com', | |
ldap.SCOPE_SUBTREE, | |
'(objectClass=groupOfNames)', | |
) | |
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn') | |
AUTH_LDAP_USER_ATTR_MAP = { | |
'first_name': 'givenName', | |
'last_name': 'sn', | |
'email': 'mail', | |
} | |
AUTH_LDAP_USER_FLAGS_BY_GROUP = { | |
'is_staff': 'cn=staff,ou=groups,dc=example,dc=com', | |
'is_superuser': 'cn=superuser,ou=groups,dc=example,dc=com', | |
} | |
# SECURITY | |
# ------------------------------------------------------------------------------ | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header | |
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect | |
SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True) | |
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure | |
SESSION_COOKIE_SECURE = True | |
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure | |
CSRF_COOKIE_SECURE = True | |
# https://docs.djangoproject.com/en/dev/topics/security/#ssl-https | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds | |
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works | |
SECURE_HSTS_SECONDS = 60 | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains | |
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool('DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True) | |
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload | |
SECURE_HSTS_PRELOAD = env.bool('DJANGO_SECURE_HSTS_PRELOAD', default=True) | |
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff | |
SECURE_CONTENT_TYPE_NOSNIFF = env.bool('DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True) | |
# TEMPLATES | |
# ------------------------------------------------------------------------------ | |
# https://docs.djangoproject.com/en/dev/ref/settings/#templates | |
TEMPLATES[0]['OPTIONS']['loaders'] = [ # noqa F405 | |
( | |
'django.template.loaders.cached.Loader', | |
[ | |
'django.template.loaders.filesystem.Loader', | |
'django.template.loaders.app_directories.Loader', | |
] | |
), | |
] | |
# ------------------------------------------------------------------------------ | |
# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email | |
DEFAULT_FROM_EMAIL = env( | |
'DJANGO_DEFAULT_FROM_EMAIL', | |
default='MPI <info@molgen.mpg.de>' | |
) | |
# https://docs.djangoproject.com/en/dev/ref/settings/#server-email | |
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL) | |
# https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix | |
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[MPI CMS]') | |
# ADMIN | |
# ------------------------------------------------------------------------------ | |
# Django Admin URL regex. | |
ADMIN_URL = env('DJANGO_ADMIN_URL') | |
# Anymail (Mailgun) | |
# ------------------------------------------------------------------------------ | |
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail | |
INSTALLED_APPS += ['anymail'] # noqa F405 | |
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' | |
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference | |
ANYMAIL = { | |
'MAILGUN_API_KEY': env('MAILGUN_API_KEY'), | |
'MAILGUN_SENDER_DOMAIN': env('MAILGUN_DOMAIN') | |
} | |
# LOGGING | |
# ------------------------------------------------------------------------------ | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'filters': { | |
'require_debug_false': { | |
'()': 'django.utils.log.RequireDebugFalse' | |
} | |
}, | |
'formatters': { | |
'verbose': { | |
'format': '%(levelname)s %(asctime)s %(module)s ' | |
'%(process)d %(thread)d %(message)s' | |
}, | |
}, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'filters': ['require_debug_false'], | |
'class': 'django.utils.log.AdminEmailHandler' | |
}, | |
'console': { | |
'level': 'DEBUG', | |
'class': 'logging.StreamHandler', | |
'formatter': 'verbose', | |
}, | |
}, | |
'loggers': { | |
'django.request': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': True | |
}, | |
'django.security.DisallowedHost': { | |
'level': 'ERROR', | |
'handlers': ['console', 'mail_admins'], | |
'propagate': True | |
} | |
} | |
} |