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.

269 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. DATABASES = {
  89. "default": {
  90. "ENGINE": "django.db.backends.sqlite3",
  91. "NAME": os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  92. }
  93. }
  94. # You can switch database engine to postgres or mysql using environment
  95. # variable 'DB'. Travis CI does this.
  96. if os.getenv("DB") == "postgres":
  97. DATABASES = {
  98. "default": {
  99. "ENGINE": "django.db.backends.postgresql",
  100. "HOST": os.getenv("DB_HOST", ""),
  101. "PORT": os.getenv("DB_PORT", ""),
  102. "NAME": os.getenv("DB_NAME", "hc"),
  103. "USER": os.getenv("DB_USER", "postgres"),
  104. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  105. "CONN_MAX_AGE": envint("DB_CONN_MAX_AGE", "0"),
  106. "TEST": {"CHARSET": "UTF8"},
  107. "OPTIONS": {
  108. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  109. "target_session_attrs": os.getenv(
  110. "DB_TARGET_SESSION_ATTRS", "read-write"
  111. ),
  112. },
  113. }
  114. }
  115. if os.getenv("DB") == "mysql":
  116. DATABASES = {
  117. "default": {
  118. "ENGINE": "django.db.backends.mysql",
  119. "HOST": os.getenv("DB_HOST", ""),
  120. "PORT": os.getenv("DB_PORT", ""),
  121. "NAME": os.getenv("DB_NAME", "hc"),
  122. "USER": os.getenv("DB_USER", "root"),
  123. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  124. "TEST": {"CHARSET": "UTF8"},
  125. }
  126. }
  127. USE_TZ = True
  128. TIME_ZONE = "UTC"
  129. LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
  130. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  131. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  132. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  133. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  134. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  135. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  136. STATIC_URL = "/static/"
  137. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  138. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  139. STATICFILES_FINDERS = (
  140. "django.contrib.staticfiles.finders.FileSystemFinder",
  141. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  142. "compressor.finders.CompressorFinder",
  143. )
  144. COMPRESS_OFFLINE = True
  145. COMPRESS_CSS_HASHING_METHOD = "content"
  146. # SMTP credentials for sending email
  147. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  148. EMAIL_PORT = envint("EMAIL_PORT", "587")
  149. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  150. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  151. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  152. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  153. # WebAuthn
  154. RP_ID = os.getenv("RP_ID")
  155. # Integrations
  156. # Apprise
  157. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  158. # Discord integration
  159. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  160. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  161. # LINE Notify
  162. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  163. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  164. # Matrix
  165. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  166. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  167. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  168. # Mattermost
  169. MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "True")
  170. # MS Teams
  171. MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
  172. # Opsgenie
  173. OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
  174. # PagerTree
  175. PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
  176. # PagerDuty
  177. PD_ENABLED = envbool("PD_ENABLED", "True")
  178. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  179. # Prometheus
  180. PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
  181. # Pushover integration
  182. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  183. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  184. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  185. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  186. # Pushbullet integration
  187. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  188. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  189. # Local shell commands
  190. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  191. # Signal
  192. SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False")
  193. # Slack integration
  194. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  195. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  196. SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
  197. # Spike.sh
  198. SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
  199. # Telegram integration -- override in local_settings.py
  200. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  201. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  202. # SMS and WhatsApp (Twilio) integration
  203. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  204. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  205. TWILIO_FROM = os.getenv("TWILIO_FROM")
  206. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  207. # Trello
  208. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  209. # VictorOps
  210. VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
  211. # Webhooks
  212. WEBHOOKS_ENABLED = envbool("WEBHOOKS_ENABLED", "True")
  213. # Zulip
  214. ZULIP_ENABLED = envbool("ZULIP_ENABLED", "True")
  215. # Read additional configuration from hc/local_settings.py if it exists
  216. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  217. from .local_settings import *