github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/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      'PAGINATE_BY_PARAM': 'page_size',
   203      'TEST_REQUEST_DEFAULT_FORMAT': 'json',
   204  }
   205  
   206  # URLs that end with slashes are ugly
   207  APPEND_SLASH = False
   208  
   209  # Determine where to send syslog messages
   210  if os.path.exists('/dev/log'):           # Linux rsyslog
   211      SYSLOG_ADDRESS = '/dev/log'
   212  elif os.path.exists('/var/log/syslog'):  # Mac OS X syslog
   213      SYSLOG_ADDRESS = '/var/log/syslog'
   214  else:                                    # default SysLogHandler address
   215      SYSLOG_ADDRESS = ('localhost', 514)
   216  
   217  # A sample logging configuration. The only tangible logging
   218  # performed by this configuration is to send an email to
   219  # the site admins on every HTTP 500 error when DEBUG=False.
   220  # See http://docs.djangoproject.com/en/dev/topics/logging for
   221  # more details on how to customize your logging configuration.
   222  LOGGING = {
   223      'version': 1,
   224      'disable_existing_loggers': False,
   225      'formatters': {
   226          'verbose': {
   227              'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
   228          },
   229          'simple': {
   230              'format': '%(levelname)s %(message)s'
   231          },
   232      },
   233      'filters': {
   234          'require_debug_false': {
   235              '()': 'django.utils.log.RequireDebugFalse'
   236          }
   237      },
   238      'handlers': {
   239          'null': {
   240              'level': 'DEBUG',
   241              'class': 'logging.NullHandler',
   242          },
   243          'console': {
   244              'level': 'DEBUG',
   245              'class': 'logging.StreamHandler',
   246              'formatter': 'simple'
   247          },
   248          'mail_admins': {
   249              'level': 'ERROR',
   250              'filters': ['require_debug_false'],
   251              'class': 'django.utils.log.AdminEmailHandler'
   252          },
   253          'rsyslog': {
   254              'class': 'logging.handlers.SysLogHandler',
   255              'address': SYSLOG_ADDRESS,
   256              'facility': 'local0',
   257          },
   258      },
   259      'loggers': {
   260          'django': {
   261              'handlers': ['null'],
   262              'level': 'INFO',
   263              'propagate': True,
   264          },
   265          'django.request': {
   266              'handlers': ['console', 'mail_admins'],
   267              'level': 'WARNING',
   268              'propagate': True,
   269          },
   270          'api': {
   271              'handlers': ['console', 'mail_admins', 'rsyslog'],
   272              'level': 'INFO',
   273              'propagate': True,
   274          },
   275      }
   276  }
   277  TEST_RUNNER = 'api.tests.SilentDjangoTestSuiteRunner'
   278  
   279  # etcd settings
   280  ETCD_HOST, ETCD_PORT = os.environ.get('ETCD', '127.0.0.1:4001').split(',')[0].split(':')
   281  
   282  # default deis settings
   283  DEIS_LOG_DIR = os.path.abspath(os.path.join(__file__, '..', '..', 'logs'))
   284  LOG_LINES = 1000
   285  TEMPDIR = tempfile.mkdtemp(prefix='deis')
   286  DEIS_DOMAIN = 'deisapp.local'
   287  
   288  # standard datetime format used for logging, model timestamps, etc.
   289  DEIS_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S%Z'
   290  
   291  # names which apps cannot reserve for routing
   292  DEIS_RESERVED_NAMES = ['deis']
   293  
   294  # default scheduler settings
   295  SCHEDULER_MODULE = 'scheduler.mock'
   296  SCHEDULER_TARGET = ''  # path to scheduler endpoint (e.g. /var/run/fleet.sock)
   297  SCHEDULER_AUTH = ''
   298  SCHEDULER_OPTIONS = {}
   299  
   300  # security keys and auth tokens
   301  SSH_PRIVATE_KEY = ''  # used for SSH connections to facilitate "deis run"
   302  SECRET_KEY = os.environ.get('DEIS_SECRET_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi')
   303  BUILDER_KEY = os.environ.get('DEIS_BUILDER_KEY', 'CHANGEME_sapm$s%upvsw5l_zuy_&29rkywd^78ff(qi')
   304  
   305  # registry settings
   306  REGISTRY_MODULE = 'registry.mock'
   307  REGISTRY_URL = 'http://localhost:5000'
   308  REGISTRY_HOST = 'localhost'
   309  REGISTRY_PORT = 5000
   310  
   311  # check if we can register users with `deis register`
   312  REGISTRATION_ENABLED = True
   313  
   314  # check if we should enable the web UI module
   315  WEB_ENABLED = False
   316  
   317  # default to sqlite3, but allow postgresql config through envvars
   318  DATABASES = {
   319      'default': {
   320          'ENGINE': 'django.db.backends.' + os.environ.get('DATABASE_ENGINE', 'postgresql_psycopg2'),
   321          'NAME': os.environ.get('DATABASE_NAME', 'deis'),
   322          # randomize test database name so we can run multiple unit tests simultaneously
   323          'TEST_NAME': "unittest-{}".format(''.join(
   324              random.choice(string.ascii_letters + string.digits) for _ in range(8)))
   325      }
   326  }
   327  
   328  APP_URL_REGEX = '[a-z0-9-]+'
   329  
   330  # Honor HTTPS from a trusted proxy
   331  # see https://docs.djangoproject.com/en/1.6/ref/settings/#secure-proxy-ssl-header
   332  SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
   333  
   334  # Unit Hostname handling.
   335  # Supports:
   336  #  default      - Docker generated hostname
   337  #  application  - Hostname based on application unit name (i.e. my-application.v2.web.1)
   338  #  server       - Hostname based on CoreOS server hostname
   339  UNIT_HOSTNAME = 'default'
   340  
   341  # LDAP DEFAULT SETTINGS (Overrided by confd later)
   342  LDAP_ENDPOINT = ""
   343  BIND_DN = ""
   344  BIND_PASSWORD = ""
   345  USER_BASEDN = ""
   346  USER_FILTER = ""
   347  GROUP_BASEDN = ""
   348  GROUP_FILTER = ""
   349  GROUP_TYPE = ""
   350  
   351  # Create a file named "local_settings.py" to contain sensitive settings data
   352  # such as database configuration, admin email, or passwords and keys. It
   353  # should also be used for any settings which differ between development
   354  # and production.
   355  # The local_settings.py file should *not* be checked in to version control.
   356  try:
   357      from .local_settings import *  # noqa
   358  except ImportError:
   359      pass
   360  
   361  # have confd_settings within container execution override all others
   362  # including local_settings (which may end up in the container)
   363  if os.path.exists('/templates/confd_settings.py'):
   364      sys.path.append('/templates')
   365      from confd_settings import *  # noqa
   366  
   367  # LDAP Backend Configuration
   368  # Should be always after the confd_settings import.
   369  LDAP_USER_SEARCH = LDAPSearch(
   370      base_dn=USER_BASEDN,
   371      scope=ldap.SCOPE_SUBTREE,
   372      filterstr="(%s=%%(user)s)" % USER_FILTER
   373  )
   374  LDAP_GROUP_SEARCH = LDAPSearch(
   375      base_dn=GROUP_BASEDN,
   376      scope=ldap.SCOPE_SUBTREE,
   377      filterstr="(%s=%s)" % (GROUP_FILTER, GROUP_TYPE)
   378  )
   379  AUTH_LDAP_SERVER_URI = LDAP_ENDPOINT
   380  AUTH_LDAP_BIND_DN = BIND_DN
   381  AUTH_LDAP_BIND_PASSWORD = BIND_PASSWORD
   382  AUTH_LDAP_USER_SEARCH = LDAP_USER_SEARCH
   383  AUTH_LDAP_GROUP_SEARCH = LDAP_GROUP_SEARCH
   384  AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
   385  AUTH_LDAP_USER_ATTR_MAP = {
   386      "first_name": "givenName",
   387      "last_name": "sn",
   388      "email": "mail",
   389      "username": USER_FILTER,
   390  }
   391  AUTH_LDAP_GLOBAL_OPTIONS = {
   392      ldap.OPT_X_TLS_REQUIRE_CERT: False,
   393      ldap.OPT_REFERRALS: False
   394  }
   395  AUTH_LDAP_ALWAYS_UPDATE_USER = True
   396  AUTH_LDAP_MIRROR_GROUPS = True
   397  AUTH_LDAP_FIND_GROUP_PERMS = True
   398  AUTH_LDAP_CACHE_GROUPS = False