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.

236 lines
7.5 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/2.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. # WebAuthn
  147. RP_ID = os.getenv("RP_ID")
  148. # Discord integration
  149. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  150. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  151. # Email integration
  152. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  153. EMAIL_PORT = envint("EMAIL_PORT", "587")
  154. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  155. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  156. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  157. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  158. # Slack integration
  159. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  160. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  161. # Pushover integration
  162. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  163. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  164. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  165. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  166. # Pushbullet integration
  167. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  168. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  169. # Telegram integration -- override in local_settings.py
  170. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  171. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  172. # SMS and WhatsApp (Twilio) integration
  173. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  174. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  175. TWILIO_FROM = os.getenv("TWILIO_FROM")
  176. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  177. # PagerDuty
  178. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  179. # Trello
  180. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  181. # Matrix
  182. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  183. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  184. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  185. # Apprise
  186. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  187. # Local shell commands
  188. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  189. # LINE Notify
  190. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  191. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  192. # Signal
  193. SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False")
  194. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  195. from .local_settings import *