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.

207 lines
6.4 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. SUPPORT_EMAIL = os.getenv("SUPPORT_EMAIL")
  25. USE_PAYMENTS = envbool("USE_PAYMENTS", "False")
  26. REGISTRATION_OPEN = envbool("REGISTRATION_OPEN", "True")
  27. INSTALLED_APPS = (
  28. 'django.contrib.admin',
  29. 'django.contrib.auth',
  30. 'django.contrib.contenttypes',
  31. 'django.contrib.humanize',
  32. 'django.contrib.sessions',
  33. 'django.contrib.messages',
  34. 'django.contrib.staticfiles',
  35. 'compressor',
  36. 'hc.accounts',
  37. 'hc.api',
  38. 'hc.front',
  39. 'hc.payments'
  40. )
  41. MIDDLEWARE = (
  42. 'django.middleware.security.SecurityMiddleware',
  43. 'django.contrib.sessions.middleware.SessionMiddleware',
  44. 'django.middleware.common.CommonMiddleware',
  45. 'django.middleware.csrf.CsrfViewMiddleware',
  46. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  47. 'django.contrib.messages.middleware.MessageMiddleware',
  48. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  49. 'hc.accounts.middleware.TeamAccessMiddleware',
  50. )
  51. AUTHENTICATION_BACKENDS = (
  52. 'hc.accounts.backends.EmailBackend',
  53. 'hc.accounts.backends.ProfileBackend'
  54. )
  55. ROOT_URLCONF = 'hc.urls'
  56. TEMPLATES = [
  57. {
  58. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  59. 'DIRS': [os.path.join(BASE_DIR, 'templates')],
  60. 'APP_DIRS': True,
  61. 'OPTIONS': {
  62. 'context_processors': [
  63. 'django.template.context_processors.debug',
  64. 'django.template.context_processors.request',
  65. 'django.contrib.auth.context_processors.auth',
  66. 'django.contrib.messages.context_processors.messages',
  67. 'hc.payments.context_processors.payments'
  68. ],
  69. },
  70. },
  71. ]
  72. WSGI_APPLICATION = 'hc.wsgi.application'
  73. TEST_RUNNER = 'hc.api.tests.CustomRunner'
  74. # Default database engine is SQLite. So one can just check out code,
  75. # install requirements.txt and do manage.py runserver and it works
  76. DATABASES = {
  77. 'default': {
  78. 'ENGINE': 'django.db.backends.sqlite3',
  79. 'NAME': os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  80. }
  81. }
  82. # You can switch database engine to postgres or mysql using environment
  83. # variable 'DB'. Travis CI does this.
  84. if os.getenv("DB") == "postgres":
  85. DATABASES = {
  86. 'default': {
  87. 'ENGINE': 'django.db.backends.postgresql',
  88. 'HOST': os.getenv("DB_HOST", ""),
  89. 'PORT': os.getenv("DB_PORT", ""),
  90. 'NAME': os.getenv("DB_NAME", "hc"),
  91. 'USER': os.getenv("DB_USER", "postgres"),
  92. 'PASSWORD': os.getenv("DB_PASSWORD", ""),
  93. 'CONN_MAX_AGE': envint("DB_CONN_MAX_AGE", "0"),
  94. 'TEST': {'CHARSET': 'UTF8'},
  95. 'OPTIONS': {
  96. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  97. "target_session_attrs": os.getenv("DB_TARGET_SESSION_ATTRS", "read-write")
  98. }
  99. }
  100. }
  101. if os.getenv("DB") == "mysql":
  102. DATABASES = {
  103. 'default': {
  104. 'ENGINE': 'django.db.backends.mysql',
  105. 'HOST': os.getenv("DB_HOST", ""),
  106. 'PORT': os.getenv("DB_PORT", ""),
  107. 'NAME': os.getenv("DB_NAME", "hc"),
  108. 'USER': os.getenv("DB_USER", "root"),
  109. 'PASSWORD': os.getenv("DB_PASSWORD", ""),
  110. 'TEST': {'CHARSET': 'UTF8'}
  111. }
  112. }
  113. TIME_ZONE = 'UTC'
  114. USE_I18N = True
  115. USE_L10N = True
  116. USE_TZ = True
  117. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  118. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  119. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  120. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  121. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  122. STATIC_URL = '/static/'
  123. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  124. STATIC_ROOT = os.path.join(BASE_DIR, 'static-collected')
  125. STATICFILES_FINDERS = (
  126. 'django.contrib.staticfiles.finders.FileSystemFinder',
  127. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  128. 'compressor.finders.CompressorFinder',
  129. )
  130. COMPRESS_OFFLINE = True
  131. COMPRESS_CSS_HASHING_METHOD = "content"
  132. # Discord integration
  133. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  134. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  135. # Email integration
  136. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  137. EMAIL_PORT = envint("EMAIL_PORT", "587")
  138. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  139. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  140. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  141. # Slack integration
  142. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  143. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  144. # Pushover integration
  145. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  146. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  147. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  148. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  149. # Pushbullet integration
  150. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  151. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  152. # Telegram integration -- override in local_settings.py
  153. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  154. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  155. # SMS (Twilio) integration
  156. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  157. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  158. TWILIO_FROM = os.getenv("TWILIO_FROM")
  159. # PagerDuty
  160. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  161. # Trello
  162. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  163. # Matrix
  164. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  165. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  166. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  167. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  168. from .local_settings import *
  169. else:
  170. warnings.warn("local_settings.py not found, using defaults")