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.

229 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. USE_I18N = True
  127. USE_L10N = False
  128. LOCALE_PATHS = (os.path.join(BASE_DIR, "locale"),)
  129. SITE_ROOT = os.getenv("SITE_ROOT", "http://localhost:8000")
  130. SITE_NAME = os.getenv("SITE_NAME", "Mychecks")
  131. MASTER_BADGE_LABEL = os.getenv("MASTER_BADGE_LABEL", SITE_NAME)
  132. PING_ENDPOINT = os.getenv("PING_ENDPOINT", SITE_ROOT + "/ping/")
  133. PING_EMAIL_DOMAIN = os.getenv("PING_EMAIL_DOMAIN", "localhost")
  134. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  135. STATIC_URL = "/static/"
  136. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  137. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  138. STATICFILES_FINDERS = (
  139. "django.contrib.staticfiles.finders.FileSystemFinder",
  140. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  141. "compressor.finders.CompressorFinder",
  142. )
  143. COMPRESS_OFFLINE = True
  144. COMPRESS_CSS_HASHING_METHOD = "content"
  145. # Discord integration
  146. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  147. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  148. # Email integration
  149. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  150. EMAIL_PORT = envint("EMAIL_PORT", "587")
  151. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  152. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  153. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  154. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  155. # Slack integration
  156. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  157. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  158. # Pushover integration
  159. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  160. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  161. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  162. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  163. # Pushbullet integration
  164. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  165. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  166. # Telegram integration -- override in local_settings.py
  167. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  168. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  169. # SMS and WhatsApp (Twilio) integration
  170. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  171. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  172. TWILIO_FROM = os.getenv("TWILIO_FROM")
  173. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  174. # PagerDuty
  175. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  176. # Trello
  177. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  178. # Matrix
  179. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  180. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  181. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  182. # Apprise
  183. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  184. # Local shell commands
  185. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  186. # LINE Notify
  187. LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
  188. LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
  189. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  190. from .local_settings import *
  191. else:
  192. warnings.warn("local_settings.py not found, using defaults")