settings.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. """
  2. Django settings for glitchtip project.
  3. Generated by 'django-admin startproject' using Django 3.0rc1.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/dev/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/dev/ref/settings/
  8. """
  9. import logging
  10. import os
  11. import sys
  12. import warnings
  13. from datetime import timedelta
  14. import environ
  15. import sentry_sdk
  16. from celery.schedules import crontab
  17. from django.core.exceptions import ImproperlyConfigured
  18. from sentry_sdk.integrations.django import DjangoIntegration
  19. from whitenoise.storage import CompressedManifestStaticFilesStorage
  20. env = environ.Env(
  21. ALLOWED_HOSTS=(list, ["*"]),
  22. AWS_ACCESS_KEY_ID=(str, None),
  23. AWS_SECRET_ACCESS_KEY=(str, None),
  24. AWS_STORAGE_BUCKET_NAME=(str, None),
  25. AWS_S3_ENDPOINT_URL=(str, None),
  26. AWS_LOCATION=(str, ""),
  27. DEBUG=(bool, False),
  28. DEBUG_TOOLBAR=(bool, False),
  29. STATIC_URL=(str, "/"),
  30. STATICFILES_STORAGE=(str, "glitchtip.settings.NoSourceMapsStorage",),
  31. )
  32. path = environ.Path()
  33. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  34. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  35. # Quick-start development settings - unsuitable for production
  36. # See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
  37. # SECURITY WARNING: keep the secret key used in production secret!
  38. SECRET_KEY = env.str("SECRET_KEY", "change_me")
  39. # SECURITY WARNING: don't run with debug turned on in production!
  40. DEBUG = env("DEBUG")
  41. # Enable only for running end to end testing. Debug must be True to use.
  42. ENABLE_TEST_API = env.bool("ENABLE_TEST_API", False)
  43. if DEBUG is False:
  44. ENABLE_TEST_API = False
  45. ALLOWED_HOSTS = env("ALLOWED_HOSTS")
  46. # Necessary for kubernetes health checks
  47. POD_IP = env.str("POD_IP", default=None)
  48. if POD_IP:
  49. ALLOWED_HOSTS.append(POD_IP)
  50. ENVIRONMENT = env.str("ENVIRONMENT", None)
  51. GLITCHTIP_VERSION = env.str("GLITCHTIP_VERSION", None)
  52. # Used in email and DSN generation. Set to full domain such as https://glitchtip.example.com
  53. default_url = env.str(
  54. "APP_URL", env.str("GLITCHTIP_DOMAIN", "http://localhost:8000")
  55. ) # DigitalOcean App Platform uses APP_URL
  56. GLITCHTIP_URL = env.url("GLITCHTIP_URL", default_url)
  57. if GLITCHTIP_URL.scheme not in ["http", "https"]:
  58. raise ImproperlyConfigured("GLITCHTIP_DOMAIN must start with http or https")
  59. # Events and associated data older than this will be deleted from the database
  60. GLITCHTIP_MAX_EVENT_LIFE_DAYS = env.int("GLITCHTIP_MAX_EVENT_LIFE_DAYS", default=90)
  61. # For development purposes only, prints out inbound event store json
  62. EVENT_STORE_DEBUG = env.bool("EVENT_STORE_DEBUG", False)
  63. # Throttle % of all transaction events. Not intended for general use. May change without warning.
  64. THROTTLE_TRANSACTION_EVENTS = env.float("THROTTLE_TRANSACTION_EVENTS", None)
  65. GLITCHTIP_ENABLE_DIFS = env.bool("GLITCHTIP_ENABLE_DIFS", False)
  66. # GlitchTip can track GlitchTip's own errors.
  67. # If enabling this, use a different server to avoid infinite loops.
  68. def before_send(event, hint):
  69. """Don't log django.DisallowedHost errors in Sentry."""
  70. if "log_record" in hint:
  71. if hint["log_record"].name == "django.security.DisallowedHost":
  72. return None
  73. return event
  74. SENTRY_DSN = env.str("SENTRY_DSN", None)
  75. # Optionally allow a different DSN for the frontend
  76. SENTRY_FRONTEND_DSN = env.str("SENTRY_FRONTEND_DSN", SENTRY_DSN)
  77. # Set traces_sample_rate to 1.0 to capture 100%. Recommended to keep this value low.
  78. # Disabled by default
  79. SENTRY_TRACES_SAMPLE_RATE = env.float("SENTRY_TRACES_SAMPLE_RATE", None)
  80. if SENTRY_DSN:
  81. release = "glitchtip@" + GLITCHTIP_VERSION if GLITCHTIP_VERSION else None
  82. sentry_sdk.init(
  83. dsn=SENTRY_DSN,
  84. integrations=[DjangoIntegration()],
  85. before_send=before_send,
  86. release=release,
  87. environment=ENVIRONMENT,
  88. auto_session_tracking=False,
  89. traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
  90. )
  91. def show_toolbar(request):
  92. return env("DEBUG_TOOLBAR")
  93. DEBUG_TOOLBAR_CONFIG = {"SHOW_TOOLBAR_CALLBACK": show_toolbar}
  94. DEBUG_TOOLBAR_PANELS = [
  95. "debug_toolbar.panels.versions.VersionsPanel",
  96. "debug_toolbar.panels.timer.TimerPanel",
  97. "debug_toolbar.panels.settings.SettingsPanel",
  98. "debug_toolbar.panels.headers.HeadersPanel",
  99. "debug_toolbar.panels.request.RequestPanel",
  100. "debug_toolbar.panels.sql.SQLPanel",
  101. ]
  102. # Application definition
  103. INSTALLED_APPS = [
  104. "django_rest_mfa.mfa_admin",
  105. "django.contrib.admin",
  106. "django.contrib.auth",
  107. "django.contrib.contenttypes",
  108. "django.contrib.sessions",
  109. "django.contrib.messages",
  110. "django.contrib.staticfiles",
  111. "django.contrib.sites",
  112. "django.contrib.postgres",
  113. "allauth",
  114. "allauth.account",
  115. "allauth.socialaccount",
  116. "allauth.socialaccount.providers.digitalocean",
  117. "allauth.socialaccount.providers.gitea",
  118. "allauth.socialaccount.providers.github",
  119. "allauth.socialaccount.providers.gitlab",
  120. "allauth.socialaccount.providers.google",
  121. "allauth.socialaccount.providers.microsoft",
  122. "allauth.socialaccount.providers.nextcloud",
  123. "anymail",
  124. "corsheaders",
  125. "django_celery_results",
  126. "django_filters",
  127. "django_extensions",
  128. "django_rest_mfa",
  129. "debug_toolbar",
  130. "rest_framework",
  131. "drf_yasg",
  132. "dj_rest_auth",
  133. "dj_rest_auth.registration",
  134. "storages",
  135. "glitchtip",
  136. "alerts",
  137. "api_tokens",
  138. "environments",
  139. "files",
  140. "organizations_ext",
  141. "events",
  142. "issues",
  143. "users",
  144. "user_reports",
  145. "glitchtip.uptime",
  146. "performance",
  147. "projects",
  148. "teams",
  149. "releases",
  150. "difs",
  151. ]
  152. # Ensure no one uses runsslserver in production
  153. if SECRET_KEY == "change_me" and DEBUG is True:
  154. INSTALLED_APPS += ["sslserver"]
  155. MIDDLEWARE = [
  156. "django.middleware.security.SecurityMiddleware",
  157. "django.contrib.sessions.middleware.SessionMiddleware",
  158. "corsheaders.middleware.CorsMiddleware",
  159. "csp.middleware.CSPMiddleware",
  160. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  161. "whitenoise.middleware.WhiteNoiseMiddleware",
  162. "debug_toolbar.middleware.DebugToolbarMiddleware",
  163. "django.middleware.common.CommonMiddleware",
  164. "django.middleware.csrf.CsrfViewMiddleware",
  165. "django.contrib.auth.middleware.AuthenticationMiddleware",
  166. "django.contrib.messages.middleware.MessageMiddleware",
  167. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  168. "sentry.middleware.proxy.DecompressBodyMiddleware",
  169. ]
  170. ROOT_URLCONF = "glitchtip.urls"
  171. TEMPLATES = [
  172. {
  173. "BACKEND": "django.template.backends.django.DjangoTemplates",
  174. "DIRS": [path("dist"), path("templates")],
  175. "APP_DIRS": True,
  176. "OPTIONS": {
  177. "context_processors": [
  178. "django.template.context_processors.debug",
  179. "django.template.context_processors.request",
  180. "django.contrib.auth.context_processors.auth",
  181. "django.contrib.messages.context_processors.messages",
  182. ],
  183. },
  184. },
  185. ]
  186. WSGI_APPLICATION = "glitchtip.wsgi.application"
  187. CORS_ORIGIN_ALLOW_ALL = env.bool("CORS_ORIGIN_ALLOW_ALL", True)
  188. CORS_ORIGIN_WHITELIST = env.tuple("CORS_ORIGIN_WHITELIST", str, default=())
  189. SECURE_BROWSER_XSS_FILTER = True
  190. CSP_DEFAULT_SRC = env.list("CSP_DEFAULT_SRC", str, ["'self'"])
  191. CSP_STYLE_SRC = env.list(
  192. "CSP_STYLE_SRC", str, ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"]
  193. )
  194. CSP_STYLE_SRC_ELEM = env.list(
  195. "CSP_STYLE_SRC_ELEM",
  196. str,
  197. ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
  198. )
  199. CSP_FONT_SRC = env.list(
  200. "CSP_FONT_SRC", str, ["'self'", "https://fonts.gstatic.com", "data:"]
  201. )
  202. # Redoc requires blob
  203. CSP_WORKER_SRC = env.list("CSP_WORKER_SRC", str, ["'self'", "blob:"])
  204. # GlitchTip can record it's own errors
  205. CSP_CONNECT_SRC = env.list(
  206. "CSP_CONNECT_SRC", str, ["'self'", "https://*.glitchtip.com"]
  207. )
  208. # Needed for Analytics and Stripe for SaaS use cases. Both are disabled by default.
  209. CSP_SCRIPT_SRC = env.list(
  210. "CSP_SCRIPT_SRC",
  211. str,
  212. ["'self'", "https://*.glitchtip.com", "https://js.stripe.com"],
  213. )
  214. CSP_IMG_SRC = env.list("CSP_IMG_SRC", str, ["'self'"])
  215. CSP_FRAME_SRC = env.list("CSP_FRAME_SRC", str, ["'self'", "https://js.stripe.com"])
  216. # Consider tracking CSP reports with GlitchTip itself
  217. CSP_REPORT_URI = env.tuple("CSP_REPORT_URI", str, None)
  218. CSP_REPORT_ONLY = env.bool("CSP_REPORT_ONLY", False)
  219. SECURE_HSTS_SECONDS = env.int("SECURE_HSTS_SECONDS", 0)
  220. SECURE_HSTS_PRELOAD = env.bool("SECURE_HSTS_PRELOAD", False)
  221. SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool("SECURE_HSTS_INCLUDE_SUBDOMAINS", False)
  222. SESSION_COOKIE_SECURE = env.bool("SESSION_COOKIE_SECURE", False)
  223. SESSION_COOKIE_SAMESITE = env.str("SESSION_COOKIE_SAMESITE", "Lax")
  224. DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", "webmaster@localhost")
  225. ANYMAIL = {
  226. "MAILGUN_API_KEY": env.str("MAILGUN_API_KEY", None),
  227. "MAILGUN_SENDER_DOMAIN": env.str("MAILGUN_SENDER_DOMAIN", None),
  228. "MAILGUN_API_URL": env.str("MAILGUN_API_URL", "https://api.mailgun.net/v3"),
  229. }
  230. ACCOUNT_EMAIL_SUBJECT_PREFIX = ""
  231. # Database
  232. # https://docs.djangoproject.com/en/dev/ref/settings/#databases
  233. DATABASES = {
  234. "default": env.db(default="postgres://postgres:postgres@postgres:5432/postgres")
  235. }
  236. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  237. # We need to support both url and broken out host to support helm redis chart
  238. REDIS_HOST = env.str("REDIS_HOST", None)
  239. if REDIS_HOST:
  240. REDIS_PORT = env.str("REDIS_PORT", "6379")
  241. REDIS_DATABASE = env.str("REDIS_DATABASE", "0")
  242. REDIS_PASSWORD = env.str("REDIS_PASSWORD", None)
  243. if REDIS_PASSWORD:
  244. REDIS_URL = (
  245. f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_DATABASE}"
  246. )
  247. else:
  248. REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DATABASE}"
  249. else:
  250. REDIS_URL = env.str("REDIS_URL", "redis://redis:6379/0")
  251. CELERY_BROKER_URL = REDIS_URL
  252. CELERY_BROKER_TRANSPORT_OPTIONS = {
  253. "fanout_prefix": True,
  254. "fanout_patterns": True,
  255. }
  256. CELERY_RESULT_BACKEND = "django-db"
  257. CELERY_CACHE_BACKEND = "django-cache"
  258. CELERY_BEAT_SCHEDULE = {
  259. "send-alert-notifications": {
  260. "task": "alerts.tasks.process_alerts",
  261. "schedule": 60,
  262. },
  263. "cleanup-old-events": {
  264. "task": "issues.tasks.cleanup_old_events",
  265. "schedule": crontab(hour=6, minute=1),
  266. },
  267. "cleanup-old-transaction-events": {
  268. "task": "performance.tasks.cleanup_old_transaction_events",
  269. "schedule": crontab(hour=6, minute=10),
  270. },
  271. "cleanup-old-monitor-checks": {
  272. "task": "glitchtip.uptime.tasks.cleanup_old_monitor_checks",
  273. "schedule": crontab(hour=6, minute=20),
  274. },
  275. "uptime-dispatch-checks": {
  276. "task": "glitchtip.uptime.tasks.dispatch_checks",
  277. "schedule": timedelta(seconds=30),
  278. },
  279. }
  280. CACHES = {"default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": REDIS_URL}}
  281. # Password validation
  282. # https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
  283. AUTH_PASSWORD_VALIDATORS = [
  284. {
  285. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  286. },
  287. {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
  288. {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
  289. {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
  290. ]
  291. # Internationalization
  292. # https://docs.djangoproject.com/en/dev/topics/i18n/
  293. LANGUAGE_CODE = "en-us"
  294. TIME_ZONE = "UTC"
  295. USE_I18N = True
  296. USE_L10N = True
  297. USE_TZ = True
  298. SITE_ID = 1
  299. # Static files (CSS, JavaScript, Images)
  300. # https://docs.djangoproject.com/en/dev/howto/static-files/
  301. STATIC_URL = "/static/"
  302. AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
  303. AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
  304. AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
  305. AWS_S3_ENDPOINT_URL = env("AWS_S3_ENDPOINT_URL")
  306. AWS_LOCATION = env("AWS_LOCATION")
  307. if AWS_S3_ENDPOINT_URL:
  308. MEDIA_URL = env.str(
  309. "MEDIA_URL", "https://%s/%s/" % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)
  310. )
  311. DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
  312. else:
  313. MEDIA_URL = "media/"
  314. MEDIA_ROOT = env.str("MEDIA_ROOT", "")
  315. STATICFILES_DIRS = [
  316. "assets",
  317. "dist",
  318. ]
  319. STATIC_ROOT = path("static/")
  320. STATICFILES_STORAGE = env("STATICFILES_STORAGE")
  321. EMAIL_BACKEND = env.str(
  322. "EMAIL_BACKEND", default="django.core.mail.backends.smtp.EmailBackend"
  323. )
  324. if os.getenv("EMAIL_URL"):
  325. EMAIL_CONFIG = env.email_url("EMAIL_URL")
  326. vars().update(EMAIL_CONFIG)
  327. AUTH_USER_MODEL = "users.User"
  328. ACCOUNT_AUTHENTICATION_METHOD = "email"
  329. ACCOUNT_EMAIL_REQUIRED = True
  330. ACCOUNT_USERNAME_REQUIRED = False
  331. ACCOUNT_USER_MODEL_USERNAME_FIELD = None
  332. ACCOUNT_ADAPTER = "glitchtip.social.MFAAccountAdapter"
  333. INVITATION_BACKEND = "organizations_ext.invitation_backend.InvitationBackend"
  334. SOCIALACCOUNT_PROVIDERS = {}
  335. GITLAB_URL = env.url("SOCIALACCOUNT_PROVIDERS_gitlab_GITLAB_URL", None)
  336. if GITLAB_URL:
  337. SOCIALACCOUNT_PROVIDERS["gitlab"] = {"GITLAB_URL": GITLAB_URL.geturl()}
  338. GITEA_URL = env.url("SOCIALACCOUNT_PROVIDERS_gitea_GITEA_URL", None)
  339. if GITEA_URL:
  340. SOCIALACCOUNT_PROVIDERS["gittea"] = {"GITEA_URL": GITEA_URL.geturl()}
  341. NEXTCLOUD_URL = env.url("SOCIALACCOUNT_PROVIDERS_nextcloud_SERVER", None)
  342. if NEXTCLOUD_URL:
  343. SOCIALACCOUNT_PROVIDERS["nextcloud"] = {"SERVER": NEXTCLOUD_URL.geturl()}
  344. OLD_PASSWORD_FIELD_ENABLED = True
  345. LOGOUT_ON_PASSWORD_CHANGE = False
  346. REST_AUTH_SERIALIZERS = {
  347. "USER_DETAILS_SERIALIZER": "users.serializers.UserSerializer",
  348. "TOKEN_SERIALIZER": "users.serializers.NoopTokenSerializer",
  349. "PASSWORD_RESET_SERIALIZER": "users.serializers.PasswordSetResetSerializer",
  350. }
  351. REST_AUTH_REGISTER_SERIALIZERS = {
  352. "REGISTER_SERIALIZER": "users.serializers.RegisterSerializer",
  353. }
  354. REST_AUTH_TOKEN_MODEL = None
  355. REST_AUTH_TOKEN_CREATOR = "users.utils.noop_token_creator"
  356. # By default (False) only the first user, superuser, or organization owners may register
  357. # and create an organization. Other users must be invited. Intended for private instances
  358. ENABLE_OPEN_USER_REGISTRATION = env.bool("ENABLE_OPEN_USER_REGISTRATION", False)
  359. AUTHENTICATION_BACKENDS = (
  360. # Needed to login by username in Django admin, regardless of `allauth`
  361. "django.contrib.auth.backends.ModelBackend",
  362. # `allauth` specific authentication methods, such as login by e-mail
  363. "allauth.account.auth_backends.AuthenticationBackend",
  364. )
  365. DEFAULT_RENDERER_CLASSES = ("rest_framework.renderers.JSONRenderer",)
  366. if DEBUG:
  367. DEFAULT_RENDERER_CLASSES = DEFAULT_RENDERER_CLASSES + (
  368. "rest_framework.renderers.BrowsableAPIRenderer",
  369. )
  370. REST_FRAMEWORK = {
  371. "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
  372. "DEFAULT_PAGINATION_CLASS": "glitchtip.pagination.LinkHeaderPagination",
  373. "PAGE_SIZE": 50,
  374. "ORDERING_PARAM": "sort",
  375. "DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
  376. "DEFAULT_RENDERER_CLASSES": DEFAULT_RENDERER_CLASSES,
  377. "DEFAULT_AUTHENTICATION_CLASSES": [
  378. "rest_framework.authentication.SessionAuthentication",
  379. "glitchtip.authentication.BearerTokenAuthentication",
  380. ],
  381. "DEFAULT_THROTTLE_RATES": {"anon": "100/minute"},
  382. }
  383. DRF_YASG_EXCLUDE_VIEWS = [
  384. "users.views.SocialAccountDisconnectView",
  385. ]
  386. SWAGGER_SETTINGS = {
  387. "DEFAULT_AUTO_SCHEMA_CLASS": "glitchtip.yasg.SquadSwaggerAutoSchema",
  388. }
  389. LOGGING_HANDLER_CLASS = env.str("DJANGO_LOGGING_HANDLER_CLASS", "logging.StreamHandler")
  390. LOGGING = {
  391. "version": 1,
  392. "disable_existing_loggers": False,
  393. "handlers": {
  394. "null": {"class": "logging.NullHandler",},
  395. "console": {"class": LOGGING_HANDLER_CLASS,},
  396. },
  397. "loggers": {
  398. "django.security.DisallowedHost": {"handlers": ["null"], "propagate": False,},
  399. },
  400. "root": {"handlers": ["console"]},
  401. }
  402. if LOGGING_HANDLER_CLASS is not logging.StreamHandler:
  403. from celery.signals import after_setup_logger, after_setup_task_logger
  404. @after_setup_logger.connect
  405. @after_setup_task_logger.connect
  406. def setup_celery_logging(logger, **kwargs):
  407. from django.utils.module_loading import import_string
  408. handler = import_string(LOGGING_HANDLER_CLASS)
  409. for h in logger.handlers:
  410. logger.removeHandler(h)
  411. logger.addHandler(handler())
  412. def organization_request_callback(request):
  413. """ Gets an organization instance from the id passed through ``request``"""
  414. user = request.user
  415. if user:
  416. return user.organizations_ext_organization.filter(
  417. owner__organization_user__user=user
  418. ).first()
  419. # Set to track activity with Plausible
  420. PLAUSIBLE_URL = env.str("PLAUSIBLE_URL", default=None)
  421. PLAUSIBLE_DOMAIN = env.str("PLAUSIBLE_DOMAIN", default=None)
  422. # Set to chatwoot website token to enable live help widget. Assumes app.chatwoot.com.
  423. CHATWOOT_WEBSITE_TOKEN = env.str("CHATWOOT_WEBSITE_TOKEN", None)
  424. # Is running unit test
  425. TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"
  426. # See https://liberapay.com/GlitchTip/donate - suggested self-host donation is $5/month/user.
  427. # Support plans available. Email info@burkesoftware.com for more info.
  428. I_PAID_FOR_GLITCHTIP = env.bool("I_PAID_FOR_GLITCHTIP", False)
  429. # Max events per month for free tier
  430. BILLING_FREE_TIER_EVENTS = env.int("BILLING_FREE_TIER_EVENTS", 1000)
  431. DJSTRIPE_SUBSCRIBER_MODEL = "organizations_ext.Organization"
  432. DJSTRIPE_SUBSCRIBER_MODEL_REQUEST_CALLBACK = organization_request_callback
  433. DJSTRIPE_USE_NATIVE_JSONFIELD = True
  434. DJSTRIPE_FOREIGN_KEY_TO_FIELD = "djstripe_id"
  435. STRIPE_AUTOMATIC_TAX = env.bool("STRIPE_AUTOMATIC_TAX", False)
  436. BILLING_ENABLED = False
  437. STRIPE_LIVE_MODE = env.bool("STRIPE_LIVE_MODE", False)
  438. if env.str("STRIPE_TEST_PUBLIC_KEY", None) or env.str("STRIPE_LIVE_PUBLIC_KEY", None):
  439. BILLING_ENABLED = True
  440. I_PAID_FOR_GLITCHTIP = True
  441. INSTALLED_APPS.append("djstripe")
  442. INSTALLED_APPS.append("djstripe_ext")
  443. STRIPE_TEST_PUBLIC_KEY = env.str("STRIPE_TEST_PUBLIC_KEY", None)
  444. STRIPE_TEST_SECRET_KEY = env.str("STRIPE_TEST_SECRET_KEY", None)
  445. STRIPE_LIVE_PUBLIC_KEY = env.str("STRIPE_LIVE_PUBLIC_KEY", None)
  446. STRIPE_LIVE_SECRET_KEY = env.str("STRIPE_LIVE_SECRET_KEY", None)
  447. DJSTRIPE_WEBHOOK_SECRET = env.str("DJSTRIPE_WEBHOOK_SECRET", None)
  448. CELERY_BEAT_SCHEDULE["set-organization-throttle"] = {
  449. "task": "organizations_ext.tasks.set_organization_throttle",
  450. "schedule": crontab(hour=7, minute=1),
  451. }
  452. CELERY_BEAT_SCHEDULE["warn-organization-throttle"] = {
  453. "task": "djstripe_ext.tasks.warn_organization_throttle",
  454. "schedule": crontab(minute=30),
  455. }
  456. elif TESTING:
  457. # Must run tests with djstripe enabled
  458. BILLING_ENABLED = True
  459. INSTALLED_APPS.append("djstripe")
  460. INSTALLED_APPS.append("djstripe_ext")
  461. STRIPE_TEST_PUBLIC_KEY = "fake"
  462. STRIPE_TEST_SECRET_KEY = "sk_test_fake" # nosec
  463. DJSTRIPE_WEBHOOK_SECRET = "whsec_fake" # nosec
  464. logging.disable(logging.WARNING)
  465. CELERY_TASK_ALWAYS_EAGER = env.bool("CELERY_TASK_ALWAYS_EAGER", False)
  466. if TESTING:
  467. CELERY_TASK_ALWAYS_EAGER = True
  468. STATICFILES_STORAGE = None
  469. # https://github.com/evansd/whitenoise/issues/215
  470. warnings.filterwarnings(
  471. "ignore", message="No directory at", module="whitenoise.base"
  472. )
  473. if CELERY_TASK_ALWAYS_EAGER:
  474. CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache",}}
  475. MFA_SERVER_NAME = "GlitchTip"
  476. FIDO_SERVER_ID = GLITCHTIP_URL.hostname
  477. # Workaround for error encountered at build time (source: https://github.com/axnsan12/drf-yasg/issues/761#issuecomment-1014530805)
  478. class NoSourceMapsStorage(CompressedManifestStaticFilesStorage):
  479. patterns = (
  480. (
  481. "*.css",
  482. (
  483. "(?P<matched>url\\(['\"]{0,1}\\s*(?P<url>.*?)[\"']{0,1}\\))",
  484. (
  485. "(?P<matched>@import\\s*[\"']\\s*(?P<url>.*?)[\"'])",
  486. '@import url("%(url)s")',
  487. ),
  488. ),
  489. ),
  490. )