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