settings.py 4.7 KB
Newer Older
David Seaward's avatar
David Seaward committed
1
import ldap
2
import strictyaml
David Seaward's avatar
David Seaward committed
3 4 5
from decouple import Config, Csv, RepositoryIni
from django_auth_ldap.config import LDAPSearch

6
import purist.limitmonitor
David Seaward's avatar
David Seaward committed
7 8 9 10 11 12 13 14
from .settings_original import *

#
# LOAD CONFIGURATION FILE
#

CONFIG_PATH = '/etc/opt/purist/middleware/config.ini'
SECRET_PATH = '/etc/opt/purist/middleware/secret.ini'
15
LINK_PROFILE_PATH = '/etc/opt/purist/middleware/link_profile.strict.yml'
David Seaward's avatar
David Seaward committed
16 17 18 19

config = Config(RepositoryIni(CONFIG_PATH))
secret_config = Config(RepositoryIni(SECRET_PATH))

20
with open(LINK_PROFILE_PATH, 'r') as stream:
21
    LINK_PROFILE_ORDERED_DICT = strictyaml.load(stream.read()).data
22

David Seaward's avatar
David Seaward committed
23 24 25 26 27 28 29 30 31
#
# SECURITY
#

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = secret_config("DJANGO_SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config("DEBUG", cast=bool)
32 33

# it is safe to use these flags in production
David Seaward's avatar
David Seaward committed
34 35 36
DEBUG_ALL_ACCESS = config("DEBUG_ALL_ACCESS", cast=bool)
DEBUG_CHANGE_PASSWORD = config("DEBUG_CHANGE_PASSWORD", cast=bool)
DEBUG_SKIP_ACTIVATION_COMMAND = config("DEBUG_SKIP_ACTIVATION_COMMAND", cast=bool)
37
DEBUG_SKIP_VALIDATE_ON_AUTHENTICATION = config("DEBUG_SKIP_VALIDATE_ON_AUTHENTICATION", cast=bool)
David Seaward's avatar
David Seaward committed
38 39 40 41 42 43 44 45

# Required if DEBUG is False
ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv())

#
# INSTALLED APPLICATIONS
#

46 47
INSTALLED_APPS += ["crispy_forms", "django_agpl", "django_celery_beat", "django_extensions", "ldapregister",
                   "limitmonitor", "purist"]
David Seaward's avatar
David Seaward committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

#
# AGPL APPLICATION
#

AGPL_ROOT = os.path.abspath(os.path.dirname(__file__) + "/..")

# no special exclusions are required, configuration and secrets are not stored in the site folder
AGPL_EXCLUDE_DIRS = [
    r'\.git$',
    r'\.idea$',
]

AGPL_FILENAME_PREFIX = 'middleware'

#
# REGISTRATION APPLICATION
#

REGISTRATION_OPEN = config("REGISTRATION_OPEN", cast=bool)

REG_PERSON_BASE_DN = config("REG_PERSON_BASE_DN")
REG_PERSON_OBJECT_CLASSES = config("REG_PERSON_OBJECT_CLASSES", cast=Csv())

REG_GROUP_BASE_DN = config("REG_GROUP_BASE_DN")
REG_GROUP_OBJECT_CLASSES = config("REG_GROUP_OBJECT_CLASSES", cast=Csv())

#
#  AUTHENTICATION
#

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'purist.custom.PassphraseValidator',
    },
]

AUTHENTICATION_BACKENDS = (
    'purist.custom.AuthenticationBackend',
)

AUTH_LDAP_SERVER_URI = config("AUTH_LDAP_SERVER_URI")
AUTH_LDAP_START_TLS = config("AUTH_LDAP_START_TLS", cast=bool)

AUTH_LDAP_BIND_DN = config("AUTH_LDAP_BIND_DN")
AUTH_LDAP_BIND_PASSWORD = secret_config("AUTH_LDAP_BIND_PASSWORD")

BASE_DN = config("AUTH_LDAP_USER_SEARCH_BASE_DN")
AUTH_LDAP_USER_SEARCH = LDAPSearch(BASE_DN, ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
# must match `base_dn` and primary key in `ldapregister.models.LdapPerson`

AUTH_USER_MODEL = 'purist.User'

#
# DATABASE
#

# See also:
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
# and https://pypi.python.org/pypi/django-ldapdb/
# (re-uses LDAP connection details from authentication settings)

SQLITE_DB_PATH = config("SQLITE_DB_PATH")

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': SQLITE_DB_PATH,
    },
    'ldap': {
        'ENGINE': 'ldapdb.backends.ldap',
        'NAME': AUTH_LDAP_SERVER_URI,
        'USER': AUTH_LDAP_BIND_DN,
        'PASSWORD': AUTH_LDAP_BIND_PASSWORD,
        'TLS': AUTH_LDAP_START_TLS,
    },
}

DATABASE_ROUTERS = ['ldapdb.router.Router']

#
# STATIC AND SITE SETTINGS
#

STATIC_ROOT = config("STATIC_ROOT")
STATICFILES_DIRS = config("STATICFILES_DIRS", cast=Csv())
SITE_TITLE = config("SITE_TITLE")
SITE_BYLINE = config("SITE_BYLINE")
SITE_DOMAIN = config("SITE_DOMAIN")
SITE_PROVIDER = config("SITE_PROVIDER")
SITE_PROVIDER_LINK = config("SITE_PROVIDER_LINK")

#
# WOOCOMMERCE
#

WOO_URL = config("WOO_URL")
WOO_WP_API = config("WOO_WP_API", cast=bool)
WOO_VERSION = config("WOO_VERSION")

WOO_CONSUMER_KEY = secret_config("WOO_CONSUMER_KEY")
WOO_CONSUMER_SECRET = secret_config("WOO_CONSUMER_SECRET")

WOO_PRODUCT_LIST = config("WOO_PRODUCT_LIST", cast=Csv(int))

#
# WOO1 PARSER
#

WOO1_FIELD_LIST = config("WOO1_FIELD_LIST", cast=Csv())

#
# SSH CONNECTION TO OPENVPN SERVER
#

OVPN_HOSTNAME = config("OVPN_HOSTNAME")
OVPN_PORT = config("OVPN_PORT", cast=int)
OVPN_USERNAME = config("OVPN_USERNAME")
OVPN_FILEPATH = config("OVPN_FILEPATH")
167

168 169 170 171 172
#
# LIMIT MONITOR
#

LM_SERVICES = purist.limitmonitor.ServicesContainer
173
LM_PARSERS = purist.limitmonitor.ParserContainer
174

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
#
# LOGGING
#

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'filters': None,
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}