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.

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