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.

214 lines
6.7 KiB

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
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(
  98. "DB_TARGET_SESSION_ATTRS", "read-write"
  99. ),
  100. },
  101. }
  102. }
  103. if os.getenv("DB") == "mysql":
  104. DATABASES = {
  105. "default": {
  106. "ENGINE": "django.db.backends.mysql",
  107. "HOST": os.getenv("DB_HOST", ""),
  108. "PORT": os.getenv("DB_PORT", ""),
  109. "NAME": os.getenv("DB_NAME", "hc"),
  110. "USER": os.getenv("DB_USER", "root"),
  111. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  112. "TEST": {"CHARSET": "UTF8"},
  113. }
  114. }
  115. TIME_ZONE = "UTC"
  116. USE_I18N = False
  117. USE_L10N = False
  118. USE_TZ = True
  119. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  120. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  121. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  122. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  123. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  124. STATIC_URL = "/static/"
  125. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  126. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  127. STATICFILES_FINDERS = (
  128. "django.contrib.staticfiles.finders.FileSystemFinder",
  129. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  130. "compressor.finders.CompressorFinder",
  131. )
  132. COMPRESS_OFFLINE = True
  133. COMPRESS_CSS_HASHING_METHOD = "content"
  134. # Discord integration
  135. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  136. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  137. # Email integration
  138. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  139. EMAIL_PORT = envint("EMAIL_PORT", "587")
  140. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  141. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  142. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  143. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  144. # Slack integration
  145. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  146. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  147. # Pushover integration
  148. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  149. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  150. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  151. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  152. # Pushbullet integration
  153. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  154. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  155. # Telegram integration -- override in local_settings.py
  156. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  157. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  158. # SMS and WhatsApp (Twilio) integration
  159. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  160. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  161. TWILIO_FROM = os.getenv("TWILIO_FROM")
  162. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  163. # PagerDuty
  164. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  165. # Trello
  166. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  167. # Matrix
  168. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  169. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  170. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  171. # Apprise
  172. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  173. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  174. from .local_settings import *
  175. else:
  176. warnings.warn("local_settings.py not found, using defaults")