github.com/amrnt/deis@v1.3.1/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  # SECURITY: change this to allowed fqdn's to prevent host poisioning attacks
    24  # https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
    25  ALLOWED_HOSTS = ['*']
    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.APIVersionMiddleware',
   111      'deis.middleware.PlatformVersionMiddleware',
   112      # Uncomment the next line for simple clickjacking protection:
   113      # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
   114  )
   115  
   116  ROOT_URLCONF = 'deis.urls'
   117  
   118  # Python dotted path to the WSGI application used by Django's runserver.
   119  WSGI_APPLICATION = 'deis.wsgi.application'
   120  
   121  TEMPLATE_DIRS = (
   122      # Put strings here, like "/home/html/django_templates"
   123      # or "C:/www/django/templates".
   124      # Always use forward slashes, even on Windows.
   125      # Don't forget to use absolute paths, not relative paths.
   126      PROJECT_ROOT + '/web/templates',
   127  )
   128  
   129  INSTALLED_APPS = (
   130      'django.contrib.admin',
   131      'django.contrib.auth',
   132      'django.contrib.contenttypes',
   133      'django.contrib.humanize',
   134      'django.contrib.messages',
   135      'django.contrib.sessions',
   136      'django.contrib.sites',
   137      'django.contrib.staticfiles',
   138      # Third-party apps
   139      'django_fsm',
   140      'guardian',
   141      'json_field',
   142      'gunicorn',
   143      'rest_framework',
   144      'rest_framework.authtoken',
   145      'south',
   146      'corsheaders',
   147      # Deis apps
   148      'api',
   149      'web',
   150  )
   151  
   152  AUTHENTICATION_BACKENDS = (
   153      "django.contrib.auth.backends.ModelBackend",
   154      "guardian.backends.ObjectPermissionBackend",
   155  )
   156  
   157  ANONYMOUS_USER_ID = -1
   158  LOGIN_URL = '/v1/auth/login/'
   159  LOGIN_REDIRECT_URL = '/'
   160  
   161  SOUTH_TESTS_MIGRATE = False
   162  
   163  CORS_ORIGIN_ALLOW_ALL = True
   164  
   165  CORS_ALLOW_HEADERS = (
   166      'content-type',
   167      'accept',
   168      'origin',
   169      'Authentication',
   170  )
   171  
   172  CORS_EXPOSE_HEADERS = (
   173      'X_DEIS_VERSION',
   174      'X_DEIS_RELEASE',
   175  )
   176  
   177  REST_FRAMEWORK = {
   178      'DEFAULT_MODEL_SERIALIZER_CLASS':
   179      'rest_framework.serializers.ModelSerializer',
   180      'DEFAULT_PERMISSION_CLASSES': (
   181          'rest_framework.permissions.IsAuthenticated',
   182      ),
   183      'DEFAULT_AUTHENTICATION_CLASSES': (
   184          'rest_framework.authentication.TokenAuthentication',
   185      ),
   186      'DEFAULT_RENDERER_CLASSES': (
   187          'rest_framework.renderers.JSONRenderer',
   188      ),
   189      'PAGINATE_BY': 100,
   190      'TEST_REQUEST_DEFAULT_FORMAT': 'json',
   191  }
   192  
   193  # URLs that end with slashes are ugly
   194  APPEND_SLASH = False
   195  
   196  # Determine where to send syslog messages
   197  if os.path.exists('/dev/log'):           # Linux rsyslog
   198      SYSLOG_ADDRESS = '/dev/log'
   199  elif os.path.exists('/var/log/syslog'):  # Mac OS X syslog
   200      SYSLOG_ADDRESS = '/var/log/syslog'
   201  else:                                    # default SysLogHandler address
   202      SYSLOG_ADDRESS = ('localhost', 514)
   203  
   204  # A sample logging configuration. The only tangible logging
   205  # performed by this configuration is to send an email to
   206  # the site admins on every HTTP 500 error when DEBUG=False.
   207  # See http://docs.djangoproject.com/en/dev/topics/logging for
   208  # more details on how to customize your logging configuration.
   209  LOGGING = {
   210      'version': 1,
   211      'disable_existing_loggers': False,
   212      'formatters': {
   213          'verbose': {
   214              'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
   215          },
   216          'simple': {
   217              'format': '%(levelname)s %(message)s'
   218          },
   219      },
   220      'filters': {
   221          'require_debug_false': {
   222              '()': 'django.utils.log.RequireDebugFalse'
   223          }
   224      },
   225      'handlers': {
   226          'null': {
   227              'level': 'DEBUG',
   228              'class': 'logging.NullHandler',
   229          },
   230          'console': {
   231              'level': 'DEBUG',
   232              'class': 'logging.StreamHandler',
   233              'formatter': 'simple'
   234          },
   235          'mail_admins': {
   236              'level': 'ERROR',
   237              'filters': ['require_debug_false'],
   238              'class': 'django.utils.log.AdminEmailHandler'
   239          },
   240          'rsyslog': {
   241              'class': 'logging.handlers.SysLogHandler',
   242              'address': SYSLOG_ADDRESS,
   243              'facility': 'local0',
   244          },
   245      },
   246      'loggers': {
   247          'django': {
   248              'handlers': ['null'],
   249              'level': 'INFO',
   250              'propagate': True,
   251          },
   252          'django.request': {
   253              'handlers': ['console', 'mail_admins'],
   254              'level': 'WARNING',
   255              'propagate': True,
   256          },
   257          'api': {
   258              'handlers': ['console', 'mail_admins', 'rsyslog'],
   259              'level': 'INFO',
   260              'propagate': True,
   261          },
   262      }
   263  }
   264  TEST_RUNNER = 'api.tests.SilentDjangoTestSuiteRunner'
   265  
   266  # etcd settings
   267  ETCD_HOST, ETCD_PORT = os.environ.get('ETCD', '127.0.0.1:4001').split(',')[0].split(':')
   268  
   269  # default deis settings
   270  DEIS_LOG_DIR = os.path.abspath(os.path.join(__file__, '..', '..', 'logs'))
   271  LOG_LINES = 1000
   272  TEMPDIR = tempfile.mkdtemp(prefix='deis')
   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  # Honor HTTPS from a trusted proxy
   312  # see https://docs.djangoproject.com/en/1.6/ref/settings/#secure-proxy-ssl-header
   313  SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
   314  
   315  # Unit Hostname handling.
   316  # Supports:
   317  #  default      - Docker generated hostname
   318  #  application  - Hostname based on application unit name (i.e. my-application.v2.web.1)
   319  #  server       - Hostname based on CoreOS server hostname
   320  UNIT_HOSTNAME = 'default'
   321  
   322  # Create a file named "local_settings.py" to contain sensitive settings data
   323  # such as database configuration, admin email, or passwords and keys. It
   324  # should also be used for any settings which differ between development
   325  # and production.
   326  # The local_settings.py file should *not* be checked in to version control.
   327  try:
   328      from .local_settings import *  # noqa
   329  except ImportError:
   330      pass
   331  
   332  
   333  # have confd_settings within container execution override all others
   334  # including local_settings (which may end up in the container)
   335  if os.path.exists('/templates/confd_settings.py'):
   336      sys.path.append('/templates')
   337      from confd_settings import *  # noqa