You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. """
  2. Django settings for healthchecks project.
  3. For the full list of settings and their values, see
  4. https://docs.djangoproject.com/en/2.1/ref/settings
  5. """
  6. import os
  7. import warnings
  8. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  9. def envbool(s, default):
  10. v = os.getenv(s, default=default)
  11. if v not in ("", "True", "False"):
  12. msg = "Unexpected value %s=%s, use 'True' or 'False'" % (s, v)
  13. raise Exception(msg)
  14. return v == "True"
  15. def envint(s, default):
  16. v = os.getenv(s, default)
  17. if v == "None":
  18. return None
  19. return int(v)
  20. SECRET_KEY = os.getenv("SECRET_KEY", "---")
  21. DEBUG = envbool("DEBUG", "True")
  22. ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "*").split(",")
  23. DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "[email protected]")
  24. USE_PAYMENTS = envbool("DEBUG", "False")
  25. REGISTRATION_OPEN = envbool("DEBUG", "True")
  26. INSTALLED_APPS = (
  27. 'django.contrib.admin',
  28. 'django.contrib.auth',
  29. 'django.contrib.contenttypes',
  30. 'django.contrib.humanize',
  31. 'django.contrib.sessions',
  32. 'django.contrib.messages',
  33. 'django.contrib.staticfiles',
  34. 'compressor',
  35. 'hc.accounts',
  36. 'hc.api',
  37. 'hc.front',
  38. 'hc.payments'
  39. )
  40. MIDDLEWARE = (
  41. 'django.middleware.security.SecurityMiddleware',
  42. 'django.contrib.sessions.middleware.SessionMiddleware',
  43. 'django.middleware.common.CommonMiddleware',
  44. 'django.middleware.csrf.CsrfViewMiddleware',
  45. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  46. 'django.contrib.messages.middleware.MessageMiddleware',
  47. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  48. 'hc.accounts.middleware.TeamAccessMiddleware',
  49. )
  50. AUTHENTICATION_BACKENDS = (
  51. 'hc.accounts.backends.EmailBackend',
  52. 'hc.accounts.backends.ProfileBackend'
  53. )
  54. ROOT_URLCONF = 'hc.urls'
  55. TEMPLATES = [
  56. {
  57. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  58. 'DIRS': [os.path.join(BASE_DIR, 'templates')],
  59. 'APP_DIRS': True,
  60. 'OPTIONS': {
  61. 'context_processors': [
  62. 'django.template.context_processors.debug',
  63. 'django.template.context_processors.request',
  64. 'django.contrib.auth.context_processors.auth',
  65. 'django.contrib.messages.context_processors.messages',
  66. 'hc.payments.context_processors.payments'
  67. ],
  68. },
  69. },
  70. ]
  71. WSGI_APPLICATION = 'hc.wsgi.application'
  72. TEST_RUNNER = 'hc.api.tests.CustomRunner'
  73. # Default database engine is SQLite. So one can just check out code,
  74. # install requirements.txt and do manage.py runserver and it works
  75. DATABASES = {
  76. 'default': {
  77. 'ENGINE': 'django.db.backends.sqlite3',
  78. 'NAME': '{0}/hc.sqlite'.format(BASE_DIR),
  79. }
  80. }
  81. # You can switch database engine to postgres or mysql using environment
  82. # variable 'DB'. Travis CI does this.
  83. if os.getenv("DB") == "postgres":
  84. DATABASES = {
  85. 'default': {
  86. 'ENGINE': 'django.db.backends.postgresql',
  87. 'HOST': os.getenv("DB_HOST", ""),
  88. 'PORT': os.getenv("DB_PORT", ""),
  89. 'NAME': os.getenv("DB_NAME", "hc"),
  90. 'USER': os.getenv("DB_USER", "postgres"),
  91. 'PASSWORD': os.getenv("DB_PASSWORD", ""),
  92. 'CONN_MAX_AGE': envint("DB_CONN_MAX_AGE", "0"),
  93. 'TEST': {'CHARSET': 'UTF8'},
  94. 'OPTIONS': {
  95. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  96. "target_session_attrs": os.getenv("DB_TARGET_SESSION_ATTRS", "read-write")
  97. }
  98. }
  99. }
  100. if os.getenv("DB") == "mysql":
  101. DATABASES = {
  102. 'default': {
  103. 'ENGINE': 'django.db.backends.mysql',
  104. 'NAME': os.getenv("DB_NAME", "hc"),
  105. 'USER': os.getenv("DB_USER", "root"),
  106. 'PASSWORD': os.getenv("DB_PASSWORD", ""),
  107. 'TEST': {'CHARSET': 'UTF8'}
  108. }
  109. }
  110. TIME_ZONE = 'UTC'
  111. USE_I18N = True
  112. USE_L10N = True
  113. USE_TZ = True
  114. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  115. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  116. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  117. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  118. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  119. STATIC_URL = '/static/'
  120. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  121. STATIC_ROOT = os.path.join(BASE_DIR, 'static-collected')
  122. STATICFILES_FINDERS = (
  123. 'django.contrib.staticfiles.finders.FileSystemFinder',
  124. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  125. 'compressor.finders.CompressorFinder',
  126. )
  127. COMPRESS_OFFLINE = True
  128. COMPRESS_CSS_HASHING_METHOD = "content"
  129. # Discord integration
  130. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  131. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  132. # Slack integration
  133. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  134. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  135. # Pushover integration
  136. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  137. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  138. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  139. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  140. # Pushbullet integration
  141. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  142. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  143. # Telegram integration -- override in local_settings.py
  144. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  145. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  146. # SMS (Twilio) integration
  147. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  148. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  149. TWILIO_FROM = os.getenv("TWILIO_FROM")
  150. # PagerDuty
  151. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  152. # Trello
  153. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  154. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  155. from .local_settings import *
  156. else:
  157. warnings.warn("local_settings.py not found, using defaults")