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.

270 lines
8.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
5 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
  1. """
  2. Django settings for healthchecks project.
  3. For the full list of settings and their values, see
  4. https://docs.djangoproject.com/en/3.1/ref/settings/
  5. """
  6. import os
  7. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. def envbool(s, default):
  9. v = os.getenv(s, default=default)
  10. if v not in ("", "True", "False"):
  11. msg = "Unexpected value %s=%s, use 'True' or 'False'" % (s, v)
  12. raise Exception(msg)
  13. return v == "True"
  14. def envint(s, default):
  15. v = os.getenv(s, default)
  16. if v == "None":
  17. return None
  18. return int(v)
  19. SECRET_KEY = os.getenv("SECRET_KEY", "---")
  20. METRICS_KEY = os.getenv("METRICS_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. VERSION = ""
  28. with open(os.path.join(BASE_DIR, "CHANGELOG.md"), encoding="utf-8") as f:
  29. for line in f.readlines():
  30. if line.startswith("## v"):
  31. VERSION = line.split()[1]
  32. break
  33. INSTALLED_APPS = (
  34. "hc.accounts",
  35. "django.contrib.admin",
  36. "django.contrib.auth",
  37. "django.contrib.contenttypes",
  38. "django.contrib.humanize",
  39. "django.contrib.sessions",
  40. "django.contrib.messages",
  41. "django.contrib.staticfiles",
  42. "compressor",
  43. "hc.api",
  44. "hc.front",
  45. "hc.payments",
  46. )
  47. MIDDLEWARE = (
  48. "django.middleware.security.SecurityMiddleware",
  49. "django.contrib.sessions.middleware.SessionMiddleware",
  50. "django.middleware.common.CommonMiddleware",
  51. "django.middleware.csrf.CsrfViewMiddleware",
  52. "django.contrib.auth.middleware.AuthenticationMiddleware",
  53. "hc.accounts.middleware.CustomHeaderMiddleware",
  54. "django.contrib.messages.middleware.MessageMiddleware",
  55. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  56. "django.middleware.locale.LocaleMiddleware",
  57. "hc.accounts.middleware.TeamAccessMiddleware",
  58. )
  59. AUTHENTICATION_BACKENDS = (
  60. "hc.accounts.backends.EmailBackend",
  61. "hc.accounts.backends.ProfileBackend",
  62. )
  63. REMOTE_USER_HEADER = os.getenv("REMOTE_USER_HEADER")
  64. if REMOTE_USER_HEADER:
  65. AUTHENTICATION_BACKENDS = ("hc.accounts.backends.CustomHeaderBackend",)
  66. ROOT_URLCONF = "hc.urls"
  67. TEMPLATES = [
  68. {
  69. "BACKEND": "django.template.backends.django.DjangoTemplates",
  70. "DIRS": [os.path.join(BASE_DIR, "templates")],
  71. "APP_DIRS": True,
  72. "OPTIONS": {
  73. "context_processors": [
  74. "django.template.context_processors.debug",
  75. "django.template.context_processors.request",
  76. "django.contrib.auth.context_processors.auth",
  77. "django.contrib.messages.context_processors.messages",
  78. "hc.front.context_processors.branding",
  79. "hc.payments.context_processors.payments",
  80. ]
  81. },
  82. }
  83. ]
  84. WSGI_APPLICATION = "hc.wsgi.application"
  85. TEST_RUNNER = "hc.api.tests.CustomRunner"
  86. # Default database engine is SQLite. So one can just check out code,
  87. # install requirements.txt and do manage.py runserver and it works
  88. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  89. DATABASES = {
  90. "default": {
  91. "ENGINE": "django.db.backends.sqlite3",
  92. "NAME": os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  93. }
  94. }
  95. # You can switch database engine to postgres or mysql using environment
  96. # variable 'DB'. Travis CI does this.
  97. if os.getenv("DB") == "postgres":
  98. DATABASES = {
  99. "default": {
  100. "ENGINE": "django.db.backends.postgresql",
  101. "HOST": os.getenv("DB_HOST", ""),
  102. "PORT": os.getenv("DB_PORT", ""),
  103. "NAME": os.getenv("DB_NAME", "hc"),
  104. "USER": os.getenv("DB_USER", "postgres"),
  105. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  106. "CONN_MAX_AGE": envint("DB_CONN_MAX_AGE", "0"),
  107. "TEST": {"CHARSET": "UTF8"},
  108. "OPTIONS": {
  109. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  110. "target_session_attrs": os.getenv(
  111. "DB_TARGET_SESSION_ATTRS", "read-write"
  112. ),
  113. },
  114. }
  115. }
  116. if os.getenv("DB") == "mysql":
  117. DATABASES = {
  118. "default": {
  119. "ENGINE": "django.db.backends.mysql",
  120. "HOST": os.getenv("DB_HOST", ""),
  121. "PORT": os.getenv("DB_PORT", ""),
  122. "NAME": os.getenv("DB_NAME", "hc"),
  123. "USER": os.getenv("DB_USER", "root"),
  124. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  125. "TEST": {"CHARSET": "UTF8"},
  126. }
  127. }
  128. USE_TZ = True
  129. TIME_ZONE = "UTC"
  130. LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
  131. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  132. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  133. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  134. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  135. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  136. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  137. STATIC_URL = "/static/"
  138. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  139. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  140. STATICFILES_FINDERS = (
  141. "django.contrib.staticfiles.finders.FileSystemFinder",
  142. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  143. "compressor.finders.CompressorFinder",
  144. )
  145. COMPRESS_OFFLINE = True
  146. COMPRESS_CSS_HASHING_METHOD = "content"
  147. # SMTP credentials for sending email
  148. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  149. EMAIL_PORT = envint("EMAIL_PORT", "587")
  150. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  151. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  152. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  153. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  154. # WebAuthn
  155. RP_ID = os.getenv("RP_ID")
  156. # Integrations
  157. # Apprise
  158. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  159. # Discord integration
  160. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  161. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  162. # LINE Notify
  163. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  164. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  165. # Matrix
  166. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  167. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  168. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  169. # Mattermost
  170. MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "True")
  171. # MS Teams
  172. MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
  173. # Opsgenie
  174. OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
  175. # PagerTree
  176. PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
  177. # PagerDuty
  178. PD_ENABLED = envbool("PD_ENABLED", "True")
  179. PD_APP_ID = os.getenv("PD_APP_ID")
  180. # Prometheus
  181. PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
  182. # Pushover integration
  183. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  184. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  185. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  186. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  187. # Pushbullet integration
  188. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  189. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  190. # Local shell commands
  191. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  192. # Signal
  193. SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False")
  194. # Slack integration
  195. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  196. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  197. SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
  198. # Spike.sh
  199. SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
  200. # Telegram integration -- override in local_settings.py
  201. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  202. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  203. # SMS and WhatsApp (Twilio) integration
  204. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  205. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  206. TWILIO_FROM = os.getenv("TWILIO_FROM")
  207. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  208. # Trello
  209. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  210. # VictorOps
  211. VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
  212. # Webhooks
  213. WEBHOOKS_ENABLED = envbool("WEBHOOKS_ENABLED", "True")
  214. # Zulip
  215. ZULIP_ENABLED = envbool("ZULIP_ENABLED", "True")
  216. # Read additional configuration from hc/local_settings.py if it exists
  217. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  218. from .local_settings import *