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.

279 lines
8.6 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. "whitenoise.middleware.WhiteNoiseMiddleware",
  50. "django.contrib.sessions.middleware.SessionMiddleware",
  51. "django.middleware.common.CommonMiddleware",
  52. "django.middleware.csrf.CsrfViewMiddleware",
  53. "django.contrib.auth.middleware.AuthenticationMiddleware",
  54. "hc.accounts.middleware.CustomHeaderMiddleware",
  55. "django.contrib.messages.middleware.MessageMiddleware",
  56. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  57. "django.middleware.locale.LocaleMiddleware",
  58. "hc.accounts.middleware.TeamAccessMiddleware",
  59. )
  60. AUTHENTICATION_BACKENDS = (
  61. "hc.accounts.backends.EmailBackend",
  62. "hc.accounts.backends.ProfileBackend",
  63. )
  64. REMOTE_USER_HEADER = os.getenv("REMOTE_USER_HEADER")
  65. if REMOTE_USER_HEADER:
  66. AUTHENTICATION_BACKENDS = ("hc.accounts.backends.CustomHeaderBackend",)
  67. ROOT_URLCONF = "hc.urls"
  68. TEMPLATES = [
  69. {
  70. "BACKEND": "django.template.backends.django.DjangoTemplates",
  71. "DIRS": [os.path.join(BASE_DIR, "templates")],
  72. "APP_DIRS": True,
  73. "OPTIONS": {
  74. "context_processors": [
  75. "django.template.context_processors.debug",
  76. "django.template.context_processors.request",
  77. "django.contrib.auth.context_processors.auth",
  78. "django.contrib.messages.context_processors.messages",
  79. "hc.front.context_processors.branding",
  80. "hc.payments.context_processors.payments",
  81. ]
  82. },
  83. }
  84. ]
  85. WSGI_APPLICATION = "hc.wsgi.application"
  86. TEST_RUNNER = "hc.api.tests.CustomRunner"
  87. # Default database engine is SQLite. So one can just check out code,
  88. # install requirements.txt and do manage.py runserver and it works
  89. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  90. DATABASES = {
  91. "default": {
  92. "ENGINE": "django.db.backends.sqlite3",
  93. "NAME": os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  94. }
  95. }
  96. # You can switch database engine to postgres or mysql using environment
  97. # variable 'DB'. Travis CI does this.
  98. if os.getenv("DB") == "postgres":
  99. DATABASES = {
  100. "default": {
  101. "ENGINE": "django.db.backends.postgresql",
  102. "HOST": os.getenv("DB_HOST", ""),
  103. "PORT": os.getenv("DB_PORT", ""),
  104. "NAME": os.getenv("DB_NAME", "hc"),
  105. "USER": os.getenv("DB_USER", "postgres"),
  106. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  107. "CONN_MAX_AGE": envint("DB_CONN_MAX_AGE", "0"),
  108. "TEST": {"CHARSET": "UTF8"},
  109. "OPTIONS": {
  110. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  111. "target_session_attrs": os.getenv(
  112. "DB_TARGET_SESSION_ATTRS", "read-write"
  113. ),
  114. },
  115. }
  116. }
  117. if os.getenv("DB") == "mysql":
  118. DATABASES = {
  119. "default": {
  120. "ENGINE": "django.db.backends.mysql",
  121. "HOST": os.getenv("DB_HOST", ""),
  122. "PORT": os.getenv("DB_PORT", ""),
  123. "NAME": os.getenv("DB_NAME", "hc"),
  124. "USER": os.getenv("DB_USER", "root"),
  125. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  126. "TEST": {"CHARSET": "UTF8"},
  127. }
  128. }
  129. USE_TZ = True
  130. TIME_ZONE = "UTC"
  131. LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
  132. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  133. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  134. SITE_LOGO_URL = os.getenv("SITE_LOGO_URL")
  135. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  136. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  137. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  138. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  139. STATIC_URL = "/static/"
  140. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  141. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  142. STATICFILES_FINDERS = (
  143. "django.contrib.staticfiles.finders.FileSystemFinder",
  144. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  145. "compressor.finders.CompressorFinder",
  146. )
  147. COMPRESS_OFFLINE = True
  148. COMPRESS_CSS_HASHING_METHOD = "content"
  149. def immutable_file_test(path, url):
  150. return url.startswith("/static/CACHE/") or url.startswith("/static/fonts/")
  151. WHITENOISE_IMMUTABLE_FILE_TEST = immutable_file_test
  152. # SMTP credentials for sending email
  153. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  154. EMAIL_PORT = envint("EMAIL_PORT", "587")
  155. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  156. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  157. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  158. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  159. # WebAuthn
  160. RP_ID = os.getenv("RP_ID")
  161. # Integrations
  162. # Apprise
  163. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  164. # Discord integration
  165. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  166. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  167. # LINE Notify
  168. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  169. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  170. # Matrix
  171. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  172. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  173. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  174. # Mattermost
  175. MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "True")
  176. # MS Teams
  177. MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
  178. # Opsgenie
  179. OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
  180. # PagerTree
  181. PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
  182. # PagerDuty
  183. PD_ENABLED = envbool("PD_ENABLED", "True")
  184. PD_APP_ID = os.getenv("PD_APP_ID")
  185. # Prometheus
  186. PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
  187. # Pushover integration
  188. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  189. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  190. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  191. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  192. # Pushbullet integration
  193. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  194. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  195. # Local shell commands
  196. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  197. # Signal
  198. SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False")
  199. # Slack integration
  200. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  201. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  202. SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
  203. # Spike.sh
  204. SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
  205. # Telegram integration -- override in local_settings.py
  206. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  207. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  208. # SMS and WhatsApp (Twilio) integration
  209. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  210. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  211. TWILIO_FROM = os.getenv("TWILIO_FROM")
  212. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  213. # Trello
  214. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  215. # VictorOps
  216. VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
  217. # Webhooks
  218. WEBHOOKS_ENABLED = envbool("WEBHOOKS_ENABLED", "True")
  219. # Zulip
  220. ZULIP_ENABLED = envbool("ZULIP_ENABLED", "True")
  221. # Read additional configuration from hc/local_settings.py if it exists
  222. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  223. from .local_settings import *