github.com/spg/deis@v1.7.3/controller/deis/settings.py (about) 1 """ 2 Django settings for the Deis project. 3 """ 4 5 from __future__ import unicode_literals 6 import os.path 7 import random 8 import string 9 import sys 10 import tempfile 11 import ldap 12 13 from django_auth_ldap.config import LDAPSearch, GroupOfNamesType 14 15 16 PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) 17 18 DEBUG = False 19 TEMPLATE_DEBUG = DEBUG 20 21 ADMINS = ( 22 # ('Your Name', 'your_email@example.com'), 23 ) 24 25 MANAGERS = ADMINS 26 27 CONN_MAX_AGE = 60 * 3 28 29 # SECURITY: change this to allowed fqdn's to prevent host poisioning attacks 30 # https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts 31 ALLOWED_HOSTS = ['*'] 32 33 # Local time zone for this installation. Choices can be found here: 34 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 35 # although not all choices may be available on all operating systems. 36 # In a Windows environment this must be set to your system time zone. 37 TIME_ZONE = 'UTC' 38 39 # Language code for this installation. All choices can be found here: 40 # http://www.i18nguy.com/unicode/language-identifiers.html 41 LANGUAGE_CODE = 'en-us' 42 43 SITE_ID = 1 44 45 # If you set this to False, Django will make some optimizations so as not 46 # to load the internationalization machinery. 47 USE_I18N = True 48 49 # If you set this to False, Django will not format dates, numbers and 50 # calendars according to the current locale. 51 USE_L10N = True 52 53 # If you set this to False, Django will not use timezone-aware datetimes. 54 USE_TZ = True 55 56 # Absolute filesystem path to the directory that will hold user-uploaded files. 57 # Example: "/var/www/example.com/media/" 58 MEDIA_ROOT = '' 59 60 # URL that handles the media served from MEDIA_ROOT. Make sure to use a 61 # trailing slash. 62 # Examples: "http://example.com/media/", "http://media.example.com/" 63 MEDIA_URL = '' 64 65 # Absolute path to the directory static files should be collected to. 66 # Don't put anything in this directory yourself; store your static files 67 # in apps' "static/" subdirectories and in STATICFILES_DIRS. 68 # Example: "/var/www/example.com/static/" 69 STATIC_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', 'static')) 70 71 # URL prefix for static files. 72 # Example: "http://example.com/static/", "http://static.example.com/" 73 STATIC_URL = '/static/' 74 75 # Additional locations of static files 76 STATICFILES_DIRS = ( 77 # Put strings here, like "/home/html/static" or "C:/www/django/static". 78 # Always use forward slashes, even on Windows. 79 # Don't forget to use absolute paths, not relative paths. 80 ) 81 82 # List of finder classes that know how to find static files in 83 # various locations. 84 STATICFILES_FINDERS = ( 85 'django.contrib.staticfiles.finders.FileSystemFinder', 86 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 87 ) 88 89 # Make this unique, and don't share it with anybody. 90 SECRET_KEY = None # @UnusedVariable 91 92 # List of callables that know how to import templates from various sources. 93 TEMPLATE_LOADERS = ( 94 'django.template.loaders.filesystem.Loader', 95 'django.template.loaders.app_directories.Loader', 96 ) 97 98 TEMPLATE_CONTEXT_PROCESSORS = ( 99 "django.contrib.auth.context_processors.auth", 100 "django.core.context_processors.debug", 101 "django.core.context_processors.i18n", 102 "django.core.context_processors.media", 103 "django.core.context_processors.request", 104 "django.core.context_processors.static", 105 "django.core.context_processors.tz", 106 "django.contrib.messages.context_processors.messages", 107 "deis.context_processors.site", 108 ) 109 110 MIDDLEWARE_CLASSES = ( 111 'corsheaders.middleware.CorsMiddleware', 112 'django.middleware.common.CommonMiddleware', 113 'django.contrib.sessions.middleware.SessionMiddleware', 114 'django.contrib.auth.middleware.AuthenticationMiddleware', 115 'django.contrib.messages.middleware.MessageMiddleware', 116 'api.middleware.APIVersionMiddleware', 117 'deis.middleware.PlatformVersionMiddleware', 118 # Uncomment the next line for simple clickjacking protection: 119 # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 120 ) 121 122 ROOT_URLCONF = 'deis.urls' 123 124 # Python dotted path to the WSGI application used by Django's runserver. 125 WSGI_APPLICATION = 'deis.wsgi.application' 126 127 TEMPLATE_DIRS = ( 128 # Put strings here, like "/home/html/django_templates" 129 # or "C:/www/django/templates". 130 # Always use forward slashes, even on Windows. 131 # Don't forget to use absolute paths, not relative paths. 132 PROJECT_ROOT + '/web/templates', 133 ) 134 135 INSTALLED_APPS = ( 136 'django.contrib.admin', 137 'django.contrib.auth', 138 'django.contrib.contenttypes', 139 'django.contrib.humanize', 140 'django.contrib.messages', 141 'django.contrib.sessions', 142 'django.contrib.sites', 143 'django.contrib.staticfiles', 144 # Third-party apps 145 'django_auth_ldap', 146 'guardian', 147 'json_field', 148 'gunicorn', 149 'rest_framework', 150 'rest_framework.authtoken', 151 'south', 152 'corsheaders', 153 # Deis apps 154 'api', 155 'web', 156 ) 157 158 AUTHENTICATION_BACKENDS = ( 159 "django_auth_ldap.backend.LDAPBackend", 160 "django.contrib.auth.backends.ModelBackend", 161 "guardian.backends.ObjectPermissionBackend", 162 ) 163 164 ANONYMOUS_USER_ID = -1 165 LOGIN_URL = '/v1/auth/login/' 166 LOGIN_REDIRECT_URL = '/' 167 168 SOUTH_TESTS_MIGRATE = False 169 170 CORS_ORIGIN_ALLOW_ALL = True 171 172 CORS_ALLOW_HEADERS = ( 173 'content-type', 174 'accept', 175 'origin', 176 'Authorization', 177 'Host', 178 ) 179 180 CORS_EXPOSE_HEADERS = ( 181 'X_DEIS_API_VERSION', # DEPRECATED 182 'X_DEIS_PLATFORM_VERSION', # DEPRECATED 183 'X-Deis-Release', # DEPRECATED 184 'DEIS_API_VERSION', 185 'DEIS_PLATFORM_VERSION', 186 'Deis-Release', 187 ) 188 189 REST_FRAMEWORK = { 190 'DEFAULT_MODEL_SERIALIZER_CLASS': 191 'rest_framework.serializers.ModelSerializer', 192 'DEFAULT_PERMISSION_CLASSES': ( 193 'rest_framework.permissions.IsAuthenticated', 194 ), 195 'DEFAULT_AUTHENTICATION_CLASSES': ( 196 'rest_framework.authentication.TokenAuthentication', 197 ), 198 'DEFAULT_RENDERER_CLASSES': ( 199 'rest_framework.renderers.JSONRenderer', 200 ), 201 'PAGINATE_BY': 100, 202 'TEST_REQUEST_DEFAULT_FORMAT': 'json', 203 } 204 205 # URLs that end with slashes are ugly 206 APPEND_SLASH = False 207 208 # Determine where to send syslog messages 209 if os.path.exists('/dev/log'): # Linux rsyslog 210 SYSLOG_ADDRESS = '/dev/log' 211 elif os.path.exists('/var/log/syslog'): # Mac OS X syslog 212 SYSLOG_ADDRESS = '/var/log/syslog' 213 else: # default SysLogHandler address 214 SYSLOG_ADDRESS = ('localhost', 514) 215 216 # A sample logging configuration. The only tangible logging 217 # performed by this configuration is to send an email to 218 # the site admins on every HTTP 500 error when DEBUG=False. 219 # See http://docs.djangoproject.com/en/dev/topics/logging for 220 # more details on how to customize your logging configuration. 221 LOGGING = { 222 'version': 1, 223 'disable_existing_loggers': False, 224 'formatters': { 225 'verbose': { 226 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' 227 }, 228 'simple': { 229 'format': '%(levelname)s %(message)s' 230 }, 231 }, 232 'filters': { 233 'require_debug_false': { 234 '()': 'django.utils.log.RequireDebugFalse' 235 } 236 }, 237 'handlers': { 238 'null': { 239 'level': 'DEBUG', 240 'class': 'logging.NullHandler', 241 }, 242 'console': { 243 'level': 'DEBUG', 244 'class': 'logging.StreamHandler', 245 'formatter': 'simple' 246 }, 247 'mail_admins': { 248 'level': 'ERROR', 249 'filters': ['require_debug_false'], 250 'class': 'django.utils.log.AdminEmailHandler' 251 }, 252 'rsyslog': { 253 'class': 'logging.handlers.SysLogHandler', 254 'address': SYSLOG_ADDRESS, 255 'facility': 'local0', 256 }, 257 }, 258 'loggers': { 259 'django': { 260 'handlers': ['null'], 261 'level': 'INFO', 262 'propagate': True, 263 }, 264 'django.request': { 265 'handlers': ['console', 'mail_admins'], 266 'level': 'WARNING', 267 'propagate': True, 268 }, 269 'api': { 270 'handlers': ['console', 'mail_admins', 'rsyslog'], 271 'level': 'INFO', 272 'propagate': True, 273 }, 274 } 275 } 276 TEST_RUNNER = 'api.tests.SilentDjangoTestSuiteRunner' 277 278 # etcd settings 279 ETCD_HOST, ETCD_PORT = os.environ.get('ETCD', '127.0.0.1:4001').split(',')[0].split(':') 280 281 # default deis settings 282 DEIS_LOG_DIR = os.path.abspath(os.path.join(__file__, '..', '..', 'logs')) 283 LOG_LINES = 1000 284 TEMPDIR = tempfile.mkdtemp(prefix='deis') 285 DEIS_DOMAIN = 'deisapp.local' 286 287 # standard datetime format used for logging, model timestamps, etc. 288 DEIS_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S%Z' 289 290 # names which apps cannot reserve for routing 291 DEIS_RESERVED_NAMES = ['deis'] 292 293 # default scheduler settings 294 SCHEDULER_MODULE = 'scheduler.mock' 295 SCHEDULER_TARGET = '' # path to scheduler endpoint (e.g. /var/run/fleet.sock) 296 SCHEDULER_AUTH = '' 297 SCHEDULER_OPTIONS = {} 298 299 # security keys and auth tokens 300 SSH_PRIVATE_KEY = '' # used for SSH connections to facilitate "deis run" 301 SECRET_KEY = os.environ.get('DEIS_SECRET_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi') 302 BUILDER_KEY = os.environ.get('DEIS_BUILDER_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi') 303 304 # registry settings 305 REGISTRY_MODULE = 'registry.mock' 306 REGISTRY_URL = 'http://localhost:5000' 307 REGISTRY_HOST = 'localhost' 308 REGISTRY_PORT = 5000 309 310 # check if we can register users with `deis register` 311 REGISTRATION_ENABLED = True 312 313 # check if we should enable the web UI module 314 WEB_ENABLED = False 315 316 # default to sqlite3, but allow postgresql config through envvars 317 DATABASES = { 318 'default': { 319 'ENGINE': 'django.db.backends.' + os.environ.get('DATABASE_ENGINE', 'postgresql_psycopg2'), 320 'NAME': os.environ.get('DATABASE_NAME', 'deis'), 321 # randomize test database name so we can run multiple unit tests simultaneously 322 'TEST_NAME': "unittest-{}".format(''.join( 323 random.choice(string.ascii_letters + string.digits) for _ in range(8))) 324 } 325 } 326 327 APP_URL_REGEX = '[a-z0-9-]+' 328 329 # Honor HTTPS from a trusted proxy 330 # see https://docs.djangoproject.com/en/1.6/ref/settings/#secure-proxy-ssl-header 331 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 332 333 # Unit Hostname handling. 334 # Supports: 335 # default - Docker generated hostname 336 # application - Hostname based on application unit name (i.e. my-application.v2.web.1) 337 # server - Hostname based on CoreOS server hostname 338 UNIT_HOSTNAME = 'default' 339 340 # LDAP DEFAULT SETTINGS (Overrided by confd later) 341 LDAP_ENDPOINT = "" 342 BIND_DN = "" 343 BIND_PASSWORD = "" 344 USER_BASEDN = "" 345 USER_FILTER = "" 346 GROUP_BASEDN = "" 347 GROUP_FILTER = "" 348 GROUP_TYPE = "" 349 350 # Create a file named "local_settings.py" to contain sensitive settings data 351 # such as database configuration, admin email, or passwords and keys. It 352 # should also be used for any settings which differ between development 353 # and production. 354 # The local_settings.py file should *not* be checked in to version control. 355 try: 356 from .local_settings import * # noqa 357 except ImportError: 358 pass 359 360 # have confd_settings within container execution override all others 361 # including local_settings (which may end up in the container) 362 if os.path.exists('/templates/confd_settings.py'): 363 sys.path.append('/templates') 364 from confd_settings import * # noqa 365 366 # LDAP Backend Configuration 367 # Should be always after the confd_settings import. 368 LDAP_USER_SEARCH = LDAPSearch( 369 base_dn=USER_BASEDN, 370 scope=ldap.SCOPE_SUBTREE, 371 filterstr="(%s=%%(user)s)" % USER_FILTER 372 ) 373 LDAP_GROUP_SEARCH = LDAPSearch( 374 base_dn=GROUP_BASEDN, 375 scope=ldap.SCOPE_SUBTREE, 376 filterstr="(%s=%s)" % (GROUP_FILTER, GROUP_TYPE) 377 ) 378 AUTH_LDAP_SERVER_URI = LDAP_ENDPOINT 379 AUTH_LDAP_BIND_DN = BIND_DN 380 AUTH_LDAP_BIND_PASSWORD = BIND_PASSWORD 381 AUTH_LDAP_USER_SEARCH = LDAP_USER_SEARCH 382 AUTH_LDAP_GROUP_SEARCH = LDAP_GROUP_SEARCH 383 AUTH_LDAP_GROUP_TYPE = GroupOfNamesType() 384 AUTH_LDAP_USER_ATTR_MAP = { 385 "first_name": "givenName", 386 "last_name": "sn", 387 "email": "mail", 388 "username": USER_FILTER, 389 } 390 AUTH_LDAP_GLOBAL_OPTIONS = { 391 ldap.OPT_X_TLS_REQUIRE_CERT: False, 392 ldap.OPT_REFERRALS: False 393 } 394 AUTH_LDAP_ALWAYS_UPDATE_USER = True 395 AUTH_LDAP_MIRROR_GROUPS = True 396 AUTH_LDAP_FIND_GROUP_PERMS = True 397 AUTH_LDAP_CACHE_GROUPS = False