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.

225 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. 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"), encoding="utf-8") as f:
  29. for line in f.readlines():
  30. if line.startswith("## v"):
  31. VERSION = line.split()[1]
  32. break
  33. INSTALLED_APPS = (
  34. "hc.accounts",
  35. "django.contrib.admin",
  36. "django.contrib.auth",
  37. "django.contrib.contenttypes",
  38. "django.contrib.humanize",
  39. "django.contrib.sessions",
  40. "django.contrib.messages",
  41. "django.contrib.staticfiles",
  42. "compressor",
  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. PING_BODY_LIMIT = envint("PING_BODY_LIMIT", "10000")
  131. STATIC_URL = "/static/"
  132. STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
  133. STATIC_ROOT = os.path.join(BASE_DIR, "static-collected")
  134. STATICFILES_FINDERS = (
  135. "django.contrib.staticfiles.finders.FileSystemFinder",
  136. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  137. "compressor.finders.CompressorFinder",
  138. )
  139. COMPRESS_OFFLINE = True
  140. COMPRESS_CSS_HASHING_METHOD = "content"
  141. # Discord integration
  142. DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
  143. DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
  144. # Email integration
  145. EMAIL_HOST = os.getenv("EMAIL_HOST", "")
  146. EMAIL_PORT = envint("EMAIL_PORT", "587")
  147. EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
  148. EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
  149. EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
  150. EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
  151. # Slack integration
  152. SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
  153. SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
  154. # Pushover integration
  155. PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
  156. PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
  157. PUSHOVER_EMERGENCY_RETRY_DELAY = int(os.getenv("PUSHOVER_EMERGENCY_RETRY_DELAY", "300"))
  158. PUSHOVER_EMERGENCY_EXPIRATION = int(os.getenv("PUSHOVER_EMERGENCY_EXPIRATION", "86400"))
  159. # Pushbullet integration
  160. PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
  161. PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
  162. # Telegram integration -- override in local_settings.py
  163. TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
  164. TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
  165. # SMS and WhatsApp (Twilio) integration
  166. TWILIO_ACCOUNT = os.getenv("TWILIO_ACCOUNT")
  167. TWILIO_AUTH = os.getenv("TWILIO_AUTH")
  168. TWILIO_FROM = os.getenv("TWILIO_FROM")
  169. TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
  170. # PagerDuty
  171. PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
  172. # Trello
  173. TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
  174. # Matrix
  175. MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
  176. MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
  177. MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
  178. # Apprise
  179. APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
  180. # Local shell commands
  181. SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
  182. if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
  183. from .local_settings import *
  184. else:
  185. warnings.warn("local_settings.py not found, using defaults")