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.

227 lines
7.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/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. "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. ROOT_URLCONF = "hc.urls"
  64. TEMPLATES = [
  65. {
  66. "BACKEND": "django.template.backends.django.DjangoTemplates",
  67. "DIRS": [os.path.join(BASE_DIR, "templates")],
  68. "APP_DIRS": True,
  69. "OPTIONS": {
  70. "context_processors": [
  71. "django.template.context_processors.debug",
  72. "django.template.context_processors.request",
  73. "django.contrib.auth.context_processors.auth",
  74. "django.contrib.messages.context_processors.messages",
  75. "hc.front.context_processors.branding",
  76. "hc.payments.context_processors.payments",
  77. ]
  78. },
  79. }
  80. ]
  81. WSGI_APPLICATION = "hc.wsgi.application"
  82. TEST_RUNNER = "hc.api.tests.CustomRunner"
  83. # Default database engine is SQLite. So one can just check out code,
  84. # install requirements.txt and do manage.py runserver and it works
  85. DATABASES = {
  86. "default": {
  87. "ENGINE": "django.db.backends.sqlite3",
  88. "NAME": os.getenv("DB_NAME", BASE_DIR + "/hc.sqlite"),
  89. }
  90. }
  91. # You can switch database engine to postgres or mysql using environment
  92. # variable 'DB'. Travis CI does this.
  93. if os.getenv("DB") == "postgres":
  94. DATABASES = {
  95. "default": {
  96. "ENGINE": "django.db.backends.postgresql",
  97. "HOST": os.getenv("DB_HOST", ""),
  98. "PORT": os.getenv("DB_PORT", ""),
  99. "NAME": os.getenv("DB_NAME", "hc"),
  100. "USER": os.getenv("DB_USER", "postgres"),
  101. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  102. "CONN_MAX_AGE": envint("DB_CONN_MAX_AGE", "0"),
  103. "TEST": {"CHARSET": "UTF8"},
  104. "OPTIONS": {
  105. "sslmode": os.getenv("DB_SSLMODE", "prefer"),
  106. "target_session_attrs": os.getenv(
  107. "DB_TARGET_SESSION_ATTRS", "read-write"
  108. ),
  109. },
  110. }
  111. }
  112. if os.getenv("DB") == "mysql":
  113. DATABASES = {
  114. "default": {
  115. "ENGINE": "django.db.backends.mysql",
  116. "HOST": os.getenv("DB_HOST", ""),
  117. "PORT": os.getenv("DB_PORT", ""),
  118. "NAME": os.getenv("DB_NAME", "hc"),
  119. "USER": os.getenv("DB_USER", "root"),
  120. "PASSWORD": os.getenv("DB_PASSWORD", ""),
  121. "TEST": {"CHARSET": "UTF8"},
  122. }
  123. }
  124. USE_TZ = True
  125. TIME_ZONE = "UTC"
  126. LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
  127. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  128. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  129. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  130. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  131. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  132. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  133. STATIC_URL = "/static/"
  134. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  135. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  136. STATICFILES_FINDERS = (
  137. "django.contrib.staticfiles.finders.FileSystemFinder",
  138. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  139. "compressor.finders.CompressorFinder",
  140. )
  141. COMPRESS_OFFLINE = True
  142. COMPRESS_CSS_HASHING_METHOD = "content"
  143. # Discord integration
  144. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  145. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  146. # Email integration
  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. # Slack integration
  154. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  155. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  156. # Pushover integration
  157. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  158. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  159. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  160. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  161. # Pushbullet integration
  162. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  163. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  164. # Telegram integration -- override in local_settings.py
  165. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  166. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  167. # SMS and WhatsApp (Twilio) integration
  168. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  169. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  170. TWILIO_FROM = os.getenv("TWILIO_FROM")
  171. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  172. # PagerDuty
  173. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  174. # Trello
  175. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  176. # Matrix
  177. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  178. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  179. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  180. # Apprise
  181. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  182. # Local shell commands
  183. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  184. # LINE Notify
  185. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  186. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  187. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  188. from .local_settings import *
  189. else:
  190. warnings.warn("local_settings.py not found, using defaults")