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.

226 lines
7.0 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
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. METRICS_KEY = os.getenv("METRICS_KEY")
  22. DEBUG = envbool("DEBUG", "True")
  23. ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "*").split(",")
  24. DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "[email protected]")
  25. SUPPORT_EMAIL = os.getenv("SUPPORT_EMAIL")
  26. USE_PAYMENTS = envbool("USE_PAYMENTS", "False")
  27. REGISTRATION_OPEN = envbool("REGISTRATION_OPEN", "True")
  28. VERSION = ""
  29. with open(os.path.join(BASE_DIR, "CHANGELOG.md"), encoding="utf-8") as f:
  30. for line in f.readlines():
  31. if line.startswith("## v"):
  32. VERSION = line.split()[1]
  33. break
  34. INSTALLED_APPS = (
  35. "hc.accounts",
  36. "django.contrib.admin",
  37. "django.contrib.auth",
  38. "django.contrib.contenttypes",
  39. "django.contrib.humanize",
  40. "django.contrib.sessions",
  41. "django.contrib.messages",
  42. "django.contrib.staticfiles",
  43. "compressor",
  44. "hc.api",
  45. "hc.front",
  46. "hc.payments",
  47. )
  48. MIDDLEWARE = (
  49. "django.middleware.security.SecurityMiddleware",
  50. "django.contrib.sessions.middleware.SessionMiddleware",
  51. "django.middleware.common.CommonMiddleware",
  52. "django.middleware.csrf.CsrfViewMiddleware",
  53. "django.contrib.auth.middleware.AuthenticationMiddleware",
  54. "django.contrib.messages.middleware.MessageMiddleware",
  55. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  56. "hc.accounts.middleware.TeamAccessMiddleware",
  57. )
  58. AUTHENTICATION_BACKENDS = (
  59. "hc.accounts.backends.EmailBackend",
  60. "hc.accounts.backends.ProfileBackend",
  61. )
  62. ROOT_URLCONF = "hc.urls"
  63. TEMPLATES = [
  64. {
  65. "BACKEND": "django.template.backends.django.DjangoTemplates",
  66. "DIRS": [os.path.join(BASE_DIR, "templates")],
  67. "APP_DIRS": True,
  68. "OPTIONS": {
  69. "context_processors": [
  70. "django.template.context_processors.debug",
  71. "django.template.context_processors.request",
  72. "django.contrib.auth.context_processors.auth",
  73. "django.contrib.messages.context_processors.messages",
  74. "hc.payments.context_processors.payments",
  75. ]
  76. },
  77. }
  78. ]
  79. WSGI_APPLICATION = "hc.wsgi.application"
  80. TEST_RUNNER = "hc.api.tests.CustomRunner"
  81. # Default database engine is SQLite. So one can just check out code,
  82. # install requirements.txt and do manage.py runserver and it works
  83. DATABASES = {
  84. "default": {
  85. "ENGINE": "django.db.backends.sqlite3",
  86. "NAME": os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  87. }
  88. }
  89. # You can switch database engine to postgres or mysql using environment
  90. # variable 'DB'. Travis CI does this.
  91. if os.getenv("DB") == "postgres":
  92. DATABASES = {
  93. "default": {
  94. "ENGINE": "django.db.backends.postgresql",
  95. "HOST": os.getenv("DB_HOST", ""),
  96. "PORT": os.getenv("DB_PORT", ""),
  97. "NAME": os.getenv("DB_NAME", "hc"),
  98. "USER": os.getenv("DB_USER", "postgres"),
  99. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  100. "CONN_MAX_AGE": envint("DB_CONN_MAX_AGE", "0"),
  101. "TEST": {"CHARSET": "UTF8"},
  102. "OPTIONS": {
  103. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  104. "target_session_attrs": os.getenv(
  105. "DB_TARGET_SESSION_ATTRS", "read-write"
  106. ),
  107. },
  108. }
  109. }
  110. if os.getenv("DB") == "mysql":
  111. DATABASES = {
  112. "default": {
  113. "ENGINE": "django.db.backends.mysql",
  114. "HOST": os.getenv("DB_HOST", ""),
  115. "PORT": os.getenv("DB_PORT", ""),
  116. "NAME": os.getenv("DB_NAME", "hc"),
  117. "USER": os.getenv("DB_USER", "root"),
  118. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  119. "TEST": {"CHARSET": "UTF8"},
  120. }
  121. }
  122. TIME_ZONE = "UTC"
  123. USE_I18N = False
  124. USE_L10N = False
  125. USE_TZ = True
  126. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  127. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  128. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  129. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  130. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  131. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  132. STATIC_URL = "/static/"
  133. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  134. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  135. STATICFILES_FINDERS = (
  136. "django.contrib.staticfiles.finders.FileSystemFinder",
  137. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  138. "compressor.finders.CompressorFinder",
  139. )
  140. COMPRESS_OFFLINE = True
  141. COMPRESS_CSS_HASHING_METHOD = "content"
  142. # Discord integration
  143. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  144. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  145. # Email integration
  146. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  147. EMAIL_PORT = envint("EMAIL_PORT", "587")
  148. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  149. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  150. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  151. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  152. # Slack integration
  153. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  154. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  155. # Pushover integration
  156. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  157. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  158. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  159. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  160. # Pushbullet integration
  161. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  162. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  163. # Telegram integration -- override in local_settings.py
  164. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  165. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  166. # SMS and WhatsApp (Twilio) integration
  167. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  168. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  169. TWILIO_FROM = os.getenv("TWILIO_FROM")
  170. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  171. # PagerDuty
  172. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  173. # Trello
  174. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  175. # Matrix
  176. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  177. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  178. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  179. # Apprise
  180. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  181. # Local shell commands
  182. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  183. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  184. from .local_settings import *
  185. else:
  186. warnings.warn("local_settings.py not found, using defaults")