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.

223 lines
6.9 KiB

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