• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / 592a6f95-a84f-4da5-b413-fedaf4c36745

28 Jun 2024 09:55PM CUT coverage: 85.417% (-0.003%) from 85.42%
592a6f95-a84f-4da5-b413-fedaf4c36745

push

circleci

web-flow
Merge pull request #4824 from mozilla/check-fxa-opt-out-for-ga4

call useMetrics hook to check FxA profile metricsEnabled

4076 of 5222 branches covered (78.05%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

3 existing lines in 2 files now uncovered.

15897 of 18161 relevant lines covered (87.53%)

10.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.44
/privaterelay/settings.py
1
"""
2
Django settings for privaterelay project.
3

4
Generated by 'django-admin startproject' using Django 2.2.2.
5

6
For more information on this file, see
7
https://docs.djangoproject.com/en/2.2/topics/settings/
8

9
For the full list of settings and their values, see
10
https://docs.djangoproject.com/en/2.2/ref/settings/
11
"""
12

13
from __future__ import annotations
1✔
14

15
import base64
1✔
16
import ipaddress
1✔
17
import os
1✔
18
import sys
1✔
19
from hashlib import sha256
1✔
20
from pathlib import Path
1✔
21
from typing import TYPE_CHECKING, Any, cast, get_args
1✔
22

23
from django.conf.global_settings import LANGUAGES as DEFAULT_LANGUAGES
1✔
24

25
import dj_database_url
1✔
26
import django_stubs_ext
1✔
27
import markus
1✔
28
import sentry_sdk
1✔
29
from csp.constants import NONE, SELF, UNSAFE_INLINE
1✔
30
from decouple import Choices, Csv, config
1✔
31
from sentry_sdk.integrations.django import DjangoIntegration
1✔
32
from sentry_sdk.integrations.logging import ignore_logger
1✔
33

34
from .types import CONTENT_SECURITY_POLICY_T, RELAY_CHANNEL_NAME
1✔
35

36
if TYPE_CHECKING:
37
    import wsgiref.headers
38

39
try:
1✔
40
    # Silk is a live profiling and inspection tool for the Django framework
41
    # https://github.com/jazzband/django-silk
42
    import silk  # noqa: F401
1✔
43

44
    HAS_SILK = True
×
45
except ImportError:
1✔
46
    HAS_SILK = False
1✔
47

48
try:
1✔
49
    import google.cloud.sqlcommenter  # noqa: F401
1✔
50

51
    HAS_SQLCOMMENTER = True
1✔
52
except ImportError:
×
53
    HAS_SQLCOMMENTER = False
×
54

55
try:
1✔
56
    from privaterelay.glean.server_events import GLEAN_EVENT_MOZLOG_TYPE
1✔
57
except ImportError:
×
58
    # File may not be generated yet. Will be checked at initialization
59
    GLEAN_EVENT_MOZLOG_TYPE = "glean-server-event"
×
60

61
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
62
BASE_DIR: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1✔
63
TMP_DIR = os.path.join(BASE_DIR, "tmp")
1✔
64
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
1✔
65

66
# Quick-start development settings - unsuitable for production
67
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
68

69
# defaulting to blank to be production-broken by default
70
SECRET_KEY = config("SECRET_KEY", None)
1✔
71
SECRET_KEY_FALLBACKS = config("SECRET_KEY_FALLBACKS", "", cast=Csv())
1✔
72
SITE_ORIGIN: str | None = config("SITE_ORIGIN", None)
1✔
73

74
ORIGIN_CHANNEL_MAP: dict[str, RELAY_CHANNEL_NAME] = {
1✔
75
    "http://127.0.0.1:8000": "local",
76
    "https://dev.fxprivaterelay.nonprod.cloudops.mozgcp.net": "dev",
77
    "https://stage.fxprivaterelay.nonprod.cloudops.mozgcp.net": "stage",
78
    "https://relay.firefox.com": "prod",
79
}
80
RELAY_CHANNEL: RELAY_CHANNEL_NAME = cast(
1✔
81
    RELAY_CHANNEL_NAME,
82
    config(
83
        "RELAY_CHANNEL",
84
        default=ORIGIN_CHANNEL_MAP.get(SITE_ORIGIN or "", "local"),
85
        cast=Choices(get_args(RELAY_CHANNEL_NAME), cast=str),
86
    ),
87
)
88

89
DEBUG = config("DEBUG", False, cast=bool)
1✔
90
if DEBUG:
1!
91
    INTERNAL_IPS = config("DJANGO_INTERNAL_IPS", default="", cast=Csv())
1✔
92
IN_PYTEST: bool = "pytest" in sys.modules
1✔
93
USE_SILK = DEBUG and HAS_SILK and not IN_PYTEST
1✔
94

95
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
96
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
1✔
97
SECURE_SSL_HOST = config("DJANGO_SECURE_SSL_HOST", None)
1✔
98
SECURE_SSL_REDIRECT = config("DJANGO_SECURE_SSL_REDIRECT", False, cast=bool)
1✔
99
SECURE_REDIRECT_EXEMPT = [
1✔
100
    r"^__version__",
101
    r"^__heartbeat__",
102
    r"^__lbheartbeat__",
103
]
104
SECURE_HSTS_INCLUDE_SUBDOMAINS = config(
1✔
105
    "DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS", False, cast=bool
106
)
107
SECURE_HSTS_PRELOAD = config("DJANGO_SECURE_HSTS_PRELOAD", False, cast=bool)
1✔
108
SECURE_HSTS_SECONDS = config("DJANGO_SECURE_HSTS_SECONDS", None)
1✔
109
SECURE_BROWSER_XSS_FILTER = config("DJANGO_SECURE_BROWSER_XSS_FILTER", True)
1✔
110
SESSION_COOKIE_SECURE = config("DJANGO_SESSION_COOKIE_SECURE", False, cast=bool)
1✔
111
CSRF_COOKIE_SECURE = config("DJANGO_CSRF_COOKIE_SECURE", False, cast=bool)
1✔
112

113
#
114
# Setup CSP
115
#
116

117
BASKET_ORIGIN = config("BASKET_ORIGIN", "https://basket.mozilla.org")
1✔
118

119
# maps FxA / Mozilla account profile hosts to respective hosts for CSP
120
FXA_BASE_ORIGIN: str = config("FXA_BASE_ORIGIN", "https://accounts.firefox.com")
1✔
121
if FXA_BASE_ORIGIN == "https://accounts.firefox.com":
1!
122
    _AVATAR_IMG_SRC = [
×
123
        "firefoxusercontent.com",
124
        "https://profile.accounts.firefox.com",
125
    ]
126
    _ACCOUNT_CONNECT_SRC = [FXA_BASE_ORIGIN]
×
127
else:
128
    if not FXA_BASE_ORIGIN == "https://accounts.stage.mozaws.net":
1!
129
        raise ValueError(
×
130
            "FXA_BASE_ORIGIN must be either https://accounts.firefox.com or https://accounts.stage.mozaws.net"
131
        )
132
    _AVATAR_IMG_SRC = [
1✔
133
        "mozillausercontent.com",
134
        "https://profile.stage.mozaws.net",
135
    ]
136
    _ACCOUNT_CONNECT_SRC = [
1✔
137
        FXA_BASE_ORIGIN,
138
        # fxaFlowTracker.ts will try this if runtimeData is slow
139
        "https://accounts.firefox.com",
140
    ]
141

142
API_DOCS_ENABLED = config("API_DOCS_ENABLED", False, cast=bool) or DEBUG
1✔
143
_CSP_SCRIPT_INLINE = API_DOCS_ENABLED or USE_SILK
1✔
144

145
# When running locally, styles might get refreshed while the server is running, so their
146
# hashes would get oudated. Hence, we just allow all of them.
147
_CSP_STYLE_INLINE = API_DOCS_ENABLED or RELAY_CHANNEL == "local"
1✔
148

149
if API_DOCS_ENABLED:
1!
150
    _API_DOCS_CSP_IMG_SRC = ["data:", "https://cdn.redoc.ly"]
1✔
151
    _API_DOCS_CSP_STYLE_SRC = ["https://fonts.googleapis.com"]
1✔
152
    _API_DOCS_CSP_FONT_SRC = ["https://fonts.gstatic.com"]
1✔
153
    _API_DOCS_CSP_WORKER_SRC = ["blob:"]
1✔
154
else:
155
    _API_DOCS_CSP_IMG_SRC = []
×
156
    _API_DOCS_CSP_STYLE_SRC = []
×
157
    _API_DOCS_CSP_FONT_SRC = []
×
158
    _API_DOCS_CSP_WORKER_SRC = []
×
159

160
# Next.js dynamically inserts the relevant styles when switching pages,
161
# by injecting them as inline styles. We need to explicitly allow those styles
162
# in our Content Security Policy.
163
_CSP_STYLE_HASHES: list[str] = []
1✔
164
if _CSP_STYLE_INLINE:
1!
165
    # 'unsafe-inline' is not compatible with hash sources
166
    _CSP_STYLE_HASHES = []
1✔
167
else:
168
    # When running in production, we want to disallow inline styles that are
169
    # not set by us, so we use an explicit allowlist with the hashes of the
170
    # styles generated by Next.js.
171
    _next_css_path = Path(STATIC_ROOT) / "_next" / "static" / "css"
×
172
    for path in _next_css_path.glob("*.css"):
×
173
        # Use sha256 hashes, to keep in sync with Chrome.
174
        # When CSP rules fail in Chrome, it provides the sha256 hash that would
175
        # have matched, useful for debugging.
176
        content = open(path, "rb").read()
×
177
        the_hash = base64.b64encode(sha256(content).digest()).decode()
×
178
        _CSP_STYLE_HASHES.append(f"'sha256-{the_hash}'")
×
179
    _CSP_STYLE_HASHES.sort()
×
180

181
    # Add the hash for an empty string (sha256-47DEQp...)
182
    # next,js injects an empty style element and then adds the content.
183
    # This hash avoids a spurious CSP error.
184
    empty_hash = base64.b64encode(sha256().digest()).decode()
×
185
    _CSP_STYLE_HASHES.append(f"'sha256-{empty_hash}'")
×
186

187
CONTENT_SECURITY_POLICY: CONTENT_SECURITY_POLICY_T = {
1✔
188
    "DIRECTIVES": {
189
        "default-src": [SELF],
190
        "connect-src": [
191
            SELF,
192
            "https://www.google-analytics.com/",
193
            "https://www.googletagmanager.com/",
194
            "https://location.services.mozilla.com",
195
            "https://api.stripe.com",
196
            BASKET_ORIGIN,
197
        ],
198
        "font-src": [SELF, "https://relay.firefox.com/"],
199
        "frame-src": ["https://js.stripe.com", "https://hooks.stripe.com"],
200
        "img-src": [SELF],
201
        "object-src": [NONE],
202
        "script-src": [
203
            SELF,
204
            "https://www.google-analytics.com/",
205
            "https://www.googletagmanager.com/",
206
            "https://js.stripe.com/",
207
        ],
208
        "style-src": [SELF],
209
    }
210
}
211
CONTENT_SECURITY_POLICY["DIRECTIVES"]["connect-src"].extend(_ACCOUNT_CONNECT_SRC)
1✔
212
CONTENT_SECURITY_POLICY["DIRECTIVES"]["font-src"].extend(_API_DOCS_CSP_FONT_SRC)
1✔
213
CONTENT_SECURITY_POLICY["DIRECTIVES"]["img-src"].extend(_AVATAR_IMG_SRC)
1✔
214
CONTENT_SECURITY_POLICY["DIRECTIVES"]["img-src"].extend(_API_DOCS_CSP_IMG_SRC)
1✔
215
CONTENT_SECURITY_POLICY["DIRECTIVES"]["style-src"].extend(_API_DOCS_CSP_STYLE_SRC)
1✔
216
CONTENT_SECURITY_POLICY["DIRECTIVES"]["style-src"].extend(_CSP_STYLE_HASHES)
1✔
217
if _CSP_STYLE_INLINE:
1!
218
    CONTENT_SECURITY_POLICY["DIRECTIVES"]["style-src"].append(UNSAFE_INLINE)
1✔
219
if _API_DOCS_CSP_WORKER_SRC:
1!
220
    CONTENT_SECURITY_POLICY["DIRECTIVES"]["worker-src"] = _API_DOCS_CSP_WORKER_SRC
1✔
221
if _CSP_REPORT_URI := config("CSP_REPORT_URI", ""):
1!
222
    CONTENT_SECURITY_POLICY["DIRECTIVES"]["report-uri"] = _CSP_REPORT_URI
×
223

224
REFERRER_POLICY = "strict-origin-when-cross-origin"
1✔
225

226
ALLOWED_HOSTS: list[str] = []
1✔
227
DJANGO_ALLOWED_HOSTS = config("DJANGO_ALLOWED_HOST", "", cast=Csv())
1✔
228
if DJANGO_ALLOWED_HOSTS:
1!
229
    ALLOWED_HOSTS += DJANGO_ALLOWED_HOSTS
×
230
DJANGO_ALLOWED_SUBNET = config("DJANGO_ALLOWED_SUBNET", None)
1✔
231
if DJANGO_ALLOWED_SUBNET:
1!
232
    ALLOWED_HOSTS += [str(ip) for ip in ipaddress.IPv4Network(DJANGO_ALLOWED_SUBNET)]
×
233

234

235
# Get our backing resource configs to check if we should install the app
236
ADMIN_ENABLED = config("ADMIN_ENABLED", False, cast=bool)
1✔
237

238

239
AWS_REGION: str | None = config("AWS_REGION", None)
1✔
240
AWS_ACCESS_KEY_ID = config("AWS_ACCESS_KEY_ID", None)
1✔
241
AWS_SECRET_ACCESS_KEY = config("AWS_SECRET_ACCESS_KEY", None)
1✔
242
AWS_SNS_TOPIC = set(config("AWS_SNS_TOPIC", "", cast=Csv()))
1✔
243
AWS_SNS_KEY_CACHE = config("AWS_SNS_KEY_CACHE", "default")
1✔
244
AWS_SES_CONFIGSET: str | None = config("AWS_SES_CONFIGSET", None)
1✔
245
AWS_SQS_EMAIL_QUEUE_URL = config("AWS_SQS_EMAIL_QUEUE_URL", None)
1✔
246
AWS_SQS_EMAIL_DLQ_URL = config("AWS_SQS_EMAIL_DLQ_URL", None)
1✔
247

248
# Dead-Letter Queue (DLQ) for SNS push subscription
249
AWS_SQS_QUEUE_URL = config("AWS_SQS_QUEUE_URL", None)
1✔
250

251
RELAY_FROM_ADDRESS: str | None = config("RELAY_FROM_ADDRESS", None)
1✔
252
GOOGLE_ANALYTICS_ID = config("GOOGLE_ANALYTICS_ID", None)
1✔
253
GA4_MEASUREMENT_ID = config("GA4_MEASUREMENT_ID", None)
1✔
254
GOOGLE_APPLICATION_CREDENTIALS: str = config("GOOGLE_APPLICATION_CREDENTIALS", "")
1✔
255
GOOGLE_CLOUD_PROFILER_CREDENTIALS_B64: str = config(
1✔
256
    "GOOGLE_CLOUD_PROFILER_CREDENTIALS_B64", ""
257
)
258
INCLUDE_VPN_BANNER = config("INCLUDE_VPN_BANNER", False, cast=bool)
1✔
259
RECRUITMENT_BANNER_LINK = config("RECRUITMENT_BANNER_LINK", None)
1✔
260
RECRUITMENT_BANNER_TEXT = config("RECRUITMENT_BANNER_TEXT", None)
1✔
261
RECRUITMENT_EMAIL_BANNER_TEXT = config("RECRUITMENT_EMAIL_BANNER_TEXT", None)
1✔
262
RECRUITMENT_EMAIL_BANNER_LINK = config("RECRUITMENT_EMAIL_BANNER_LINK", None)
1✔
263

264
PHONES_ENABLED: bool = config("PHONES_ENABLED", False, cast=bool)
1✔
265
PHONES_NO_CLIENT_CALLS_IN_TEST = False  # Override in tests that do not test clients
1✔
266
TWILIO_ACCOUNT_SID: str | None = config("TWILIO_ACCOUNT_SID", None)
1✔
267
TWILIO_AUTH_TOKEN: str | None = config("TWILIO_AUTH_TOKEN", None)
1✔
268
TWILIO_MAIN_NUMBER: str | None = config("TWILIO_MAIN_NUMBER", None)
1✔
269
TWILIO_SMS_APPLICATION_SID: str | None = config("TWILIO_SMS_APPLICATION_SID", None)
1✔
270
TWILIO_MESSAGING_SERVICE_SID: list[str] = config(
1✔
271
    "TWILIO_MESSAGING_SERVICE_SID", "", cast=Csv()
272
)
273
TWILIO_TEST_ACCOUNT_SID: str | None = config("TWILIO_TEST_ACCOUNT_SID", None)
1✔
274
TWILIO_TEST_AUTH_TOKEN: str | None = config("TWILIO_TEST_AUTH_TOKEN", None)
1✔
275
TWILIO_ALLOWED_COUNTRY_CODES = {
1✔
276
    code.upper() for code in config("TWILIO_ALLOWED_COUNTRY_CODES", "US,CA", cast=Csv())
277
}
278
MAX_MINUTES_TO_VERIFY_REAL_PHONE: int = config(
1✔
279
    "MAX_MINUTES_TO_VERIFY_REAL_PHONE", 5, cast=int
280
)
281
MAX_TEXTS_PER_BILLING_CYCLE: int = config("MAX_TEXTS_PER_BILLING_CYCLE", 75, cast=int)
1✔
282
MAX_MINUTES_PER_BILLING_CYCLE: int = config(
1✔
283
    "MAX_MINUTES_PER_BILLING_CYCLE", 50, cast=int
284
)
285
DAYS_PER_BILLING_CYCLE = config("DAYS_PER_BILLING_CYCLE", 30, cast=int)
1✔
286
MAX_DAYS_IN_MONTH = 31
1✔
287
IQ_ENABLED = config("IQ_ENABLED", False, cast=bool)
1✔
288
IQ_FOR_VERIFICATION: bool = config("IQ_FOR_VERIFICATION", False, cast=bool)
1✔
289
IQ_FOR_NEW_NUMBERS = config("IQ_FOR_NEW_NUMBERS", False, cast=bool)
1✔
290
IQ_MAIN_NUMBER: str = config("IQ_MAIN_NUMBER", "")
1✔
291
IQ_OUTBOUND_API_KEY: str = config("IQ_OUTBOUND_API_KEY", "")
1✔
292
IQ_INBOUND_API_KEY = config("IQ_INBOUND_API_KEY", "")
1✔
293
IQ_MESSAGE_API_ORIGIN = config(
1✔
294
    "IQ_MESSAGE_API_ORIGIN", "https://messagebroker.inteliquent.com"
295
)
296
IQ_MESSAGE_PATH = "/msgbroker/rest/publishMessages"
1✔
297
IQ_PUBLISH_MESSAGE_URL: str = f"{IQ_MESSAGE_API_ORIGIN}{IQ_MESSAGE_PATH}"
1✔
298

299
DJANGO_STATSD_ENABLED = config("DJANGO_STATSD_ENABLED", False, cast=bool)
1✔
300
STATSD_DEBUG = config("STATSD_DEBUG", False, cast=bool)
1✔
301
STATSD_ENABLED: bool = DJANGO_STATSD_ENABLED or STATSD_DEBUG
1✔
302
STATSD_HOST = config("DJANGO_STATSD_HOST", "127.0.0.1")
1✔
303
STATSD_PORT = config("DJANGO_STATSD_PORT", "8125")
1✔
304
STATSD_PREFIX = config("DJANGO_STATSD_PREFIX", "fx.private.relay")
1✔
305

306
SERVE_ADDON = config("SERVE_ADDON", None)
1✔
307

308
# Application definition
309
INSTALLED_APPS = [
1✔
310
    "whitenoise.runserver_nostatic",
311
    "django.contrib.staticfiles",
312
    "django.contrib.auth",
313
    "django.contrib.contenttypes",
314
    "django.contrib.sessions",
315
    "django.contrib.messages",
316
    "django.contrib.sites",
317
    "django_filters",
318
    "django_ftl.apps.DjangoFtlConfig",
319
    "dockerflow.django",
320
    "allauth",
321
    "allauth.account",
322
    "allauth.socialaccount",
323
    "allauth.socialaccount.providers.fxa",
324
    "rest_framework",
325
    "rest_framework.authtoken",
326
    "corsheaders",
327
    "csp",
328
    "waffle",
329
    "privaterelay.apps.PrivateRelayConfig",
330
    "api.apps.ApiConfig",
331
]
332

333
if API_DOCS_ENABLED:
1!
334
    INSTALLED_APPS += [
1✔
335
        "drf_spectacular",
336
        "drf_spectacular_sidecar",
337
    ]
338

339
if DEBUG:
1!
340
    INSTALLED_APPS += [
1✔
341
        "debug_toolbar",
342
    ]
343

344
if USE_SILK:
1!
345
    INSTALLED_APPS.append("silk")
×
346

347
if ADMIN_ENABLED:
1!
348
    INSTALLED_APPS += [
×
349
        "django.contrib.admin",
350
    ]
351

352
if AWS_SES_CONFIGSET and AWS_SNS_TOPIC:
1!
353
    INSTALLED_APPS += [
1✔
354
        "emails.apps.EmailsConfig",
355
    ]
356

357
if PHONES_ENABLED:
1!
358
    INSTALLED_APPS += [
1✔
359
        "phones.apps.PhonesConfig",
360
    ]
361

362

363
MIDDLEWARE = ["privaterelay.middleware.ResponseMetrics"]
1✔
364

365
if USE_SILK:
1!
366
    MIDDLEWARE.append("silk.middleware.SilkyMiddleware")
×
367
if DEBUG:
1!
368
    MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
1✔
369

370
MIDDLEWARE += [
1✔
371
    "django.middleware.security.SecurityMiddleware",
372
    "csp.middleware.CSPMiddleware",
373
    "privaterelay.middleware.RedirectRootIfLoggedIn",
374
    "privaterelay.middleware.RelayStaticFilesMiddleware",
375
    "django.contrib.sessions.middleware.SessionMiddleware",
376
    "corsheaders.middleware.CorsMiddleware",
377
    "django.middleware.common.CommonMiddleware",
378
    "django.middleware.csrf.CsrfViewMiddleware",
379
    "django.contrib.auth.middleware.AuthenticationMiddleware",
380
    "django.contrib.messages.middleware.MessageMiddleware",
381
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
382
    "django.middleware.locale.LocaleMiddleware",
383
    "allauth.account.middleware.AccountMiddleware",
384
    "django_ftl.middleware.activate_from_request_language_code",
385
    "django_referrer_policy.middleware.ReferrerPolicyMiddleware",
386
    "dockerflow.django.middleware.DockerflowMiddleware",
387
    "waffle.middleware.WaffleMiddleware",
388
    "privaterelay.middleware.AddDetectedCountryToRequestAndResponseHeaders",
389
    "privaterelay.middleware.StoreFirstVisit",
390
]
391

392
if HAS_SQLCOMMENTER:
1!
393
    MIDDLEWARE.append("google.cloud.sqlcommenter.django.middleware.SqlCommenter")
1✔
394

395
ROOT_URLCONF = "privaterelay.urls"
1✔
396

397
TEMPLATES = [
1✔
398
    {
399
        "BACKEND": "django.template.backends.django.DjangoTemplates",
400
        "DIRS": [
401
            os.path.join(BASE_DIR, "privaterelay", "templates"),
402
        ],
403
        "APP_DIRS": True,
404
        "OPTIONS": {
405
            "context_processors": [
406
                "django.template.context_processors.debug",
407
                "django.template.context_processors.request",
408
                "django.contrib.auth.context_processors.auth",
409
                "django.contrib.messages.context_processors.messages",
410
            ],
411
        },
412
    },
413
]
414

415
RELAY_FIREFOX_DOMAIN: str = config("RELAY_FIREFOX_DOMAIN", "relay.firefox.com")
1✔
416
MOZMAIL_DOMAIN: str = config("MOZMAIL_DOMAIN", "mozmail.com")
1✔
417
MAX_NUM_FREE_ALIASES: int = config("MAX_NUM_FREE_ALIASES", 5, cast=int)
1✔
418
PERIODICAL_PREMIUM_PROD_ID: str = config("PERIODICAL_PREMIUM_PROD_ID", "")
1✔
419
PREMIUM_PLAN_ID_US_MONTHLY: str = config(
1✔
420
    "PREMIUM_PLAN_ID_US_MONTHLY", "price_1LXUcnJNcmPzuWtRpbNOajYS"
421
)
422
PREMIUM_PLAN_ID_US_YEARLY: str = config(
1✔
423
    "PREMIUM_PLAN_ID_US_YEARLY", "price_1LXUdlJNcmPzuWtRKTYg7mpZ"
424
)
425
PHONE_PROD_ID = config("PHONE_PROD_ID", "")
1✔
426
PHONE_PLAN_ID_US_MONTHLY: str = config(
1✔
427
    "PHONE_PLAN_ID_US_MONTHLY", "price_1Li0w8JNcmPzuWtR2rGU80P3"
428
)
429
PHONE_PLAN_ID_US_YEARLY: str = config(
1✔
430
    "PHONE_PLAN_ID_US_YEARLY", "price_1Li15WJNcmPzuWtRIh0F4VwP"
431
)
432
BUNDLE_PROD_ID = config("BUNDLE_PROD_ID", "")
1✔
433
BUNDLE_PLAN_ID_US: str = config("BUNDLE_PLAN_ID_US", "price_1LwoSDJNcmPzuWtR6wPJZeoh")
1✔
434

435
SUBSCRIPTIONS_WITH_UNLIMITED: list[str] = config(
1✔
436
    "SUBSCRIPTIONS_WITH_UNLIMITED", default="", cast=Csv()
437
)
438
SUBSCRIPTIONS_WITH_PHONE: list[str] = config(
1✔
439
    "SUBSCRIPTIONS_WITH_PHONE", default="", cast=Csv()
440
)
441
SUBSCRIPTIONS_WITH_VPN: list[str] = config(
1✔
442
    "SUBSCRIPTIONS_WITH_VPN", default="", cast=Csv()
443
)
444

445
MAX_ONBOARDING_AVAILABLE = config("MAX_ONBOARDING_AVAILABLE", 0, cast=int)
1✔
446
MAX_ONBOARDING_FREE_AVAILABLE = config("MAX_ONBOARDING_FREE_AVAILABLE", 3, cast=int)
1✔
447

448
MAX_ADDRESS_CREATION_PER_DAY = config("MAX_ADDRESS_CREATION_PER_DAY", 100, cast=int)
1✔
449
MAX_REPLIES_PER_DAY = config("MAX_REPLIES_PER_DAY", 100, cast=int)
1✔
450
MAX_FORWARDED_PER_DAY = config("MAX_FORWARDED_PER_DAY", 1000, cast=int)
1✔
451
MAX_FORWARDED_EMAIL_SIZE_PER_DAY = config(
1✔
452
    "MAX_FORWARDED_EMAIL_SIZE_PER_DAY", 1_000_000_000, cast=int
453
)
454
PREMIUM_FEATURE_PAUSED_DAYS: int = config(
1✔
455
    "ACCOUNT_PREMIUM_FEATURE_PAUSED_DAYS", 1, cast=int
456
)
457

458
SOFT_BOUNCE_ALLOWED_DAYS: int = config("SOFT_BOUNCE_ALLOWED_DAYS", 1, cast=int)
1✔
459
HARD_BOUNCE_ALLOWED_DAYS: int = config("HARD_BOUNCE_ALLOWED_DAYS", 30, cast=int)
1✔
460

461
WSGI_APPLICATION = "privaterelay.wsgi.application"
1✔
462

463
# Database
464
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
465

466
DATABASES = {
1✔
467
    "default": dj_database_url.config(
468
        default="sqlite:///{}".format(os.path.join(BASE_DIR, "db.sqlite3"))
469
    )
470
}
471
# Optionally set a test database name.
472
# This is useful for forcing an on-disk database for SQLite.
473
TEST_DB_NAME = config("TEST_DB_NAME", "")
1✔
474
if TEST_DB_NAME:
1!
475
    DATABASES["default"]["TEST"] = {"NAME": TEST_DB_NAME}
×
476

477
REDIS_URL = config("REDIS_URL", "")
1✔
478
if REDIS_URL:
1!
479
    CACHES = {
×
480
        "default": {
481
            "BACKEND": "django_redis.cache.RedisCache",
482
            "LOCATION": REDIS_URL,
483
            "OPTIONS": {
484
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
485
            },
486
        }
487
    }
488
    SESSION_ENGINE = "django.contrib.sessions.backends.cache"
×
489
    SESSION_CACHE_ALIAS = "default"
×
490
elif RELAY_CHANNEL == "local":
1!
491
    CACHES = {
1✔
492
        "default": {
493
            "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
494
        }
495
    }
496

497
# Password validation
498
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
499
# only needed when admin UI is enabled
500
if ADMIN_ENABLED:
1!
501
    _DJANGO_PWD_VALIDATION = "django.contrib.auth.password_validation"  # noqa: E501, S105 (long line, possible password)
×
502
    AUTH_PASSWORD_VALIDATORS = [
×
503
        {"NAME": _DJANGO_PWD_VALIDATION + ".UserAttributeSimilarityValidator"},
504
        {"NAME": _DJANGO_PWD_VALIDATION + ".MinimumLengthValidator"},
505
        {"NAME": _DJANGO_PWD_VALIDATION + ".CommonPasswordValidator"},
506
        {"NAME": _DJANGO_PWD_VALIDATION + ".NumericPasswordValidator"},
507
    ]
508

509

510
# Internationalization
511
# https://docs.djangoproject.com/en/2.2/topics/i18n/
512

513
LANGUAGE_CODE = "en"
1✔
514

515
# Mozilla l10n directories use lang-locale language codes,
516
# so we need to add those to LANGUAGES so Django's LocaleMiddleware
517
# can find them.
518
LANGUAGES = DEFAULT_LANGUAGES + [
1✔
519
    ("zh-tw", "Chinese"),
520
    ("zh-cn", "Chinese"),
521
    ("es-es", "Spanish"),
522
    ("pt-pt", "Portuguese"),
523
    ("skr", "Saraiki"),
524
]
525

526
TIME_ZONE = "UTC"
1✔
527

528
USE_I18N = True
1✔
529

530

531
USE_TZ = True
1✔
532

533
STATICFILES_DIRS = [
1✔
534
    os.path.join(BASE_DIR, "frontend/out"),
535
]
536
# Static files (the front-end in /frontend/)
537
# https://whitenoise.evans.io/en/stable/django.html#using-whitenoise-with-webpack-browserify-latest-js-thing
538
STATIC_URL = "/"
1✔
539
if DEBUG:
1!
540
    # In production, we run collectstatic to index all static files.
541
    # However, when running locally, we want to automatically pick up
542
    # all files spewed out by `npm run watch` in /frontend/out,
543
    # and we're fine with the performance impact of that.
544
    WHITENOISE_ROOT = os.path.join(BASE_DIR, "frontend/out")
1✔
545
STORAGES = {
1✔
546
    "default": {
547
        "BACKEND": "django.core.files.storage.FileSystemStorage",
548
    },
549
    "staticfiles": {
550
        "BACKEND": "privaterelay.storage.RelayStaticFilesStorage",
551
    },
552
}
553

554
# Relay does not support user-uploaded files
555
MEDIA_ROOT = None
1✔
556
MEDIA_URL = None
1✔
557

558
WHITENOISE_INDEX_FILE = True
1✔
559

560

561
# See
562
# https://whitenoise.evans.io/en/stable/django.html#WHITENOISE_ADD_HEADERS_FUNCTION
563
# Intended to ensure that the homepage does not get cached in our CDN,
564
# so that the `RedirectRootIfLoggedIn` middleware can kick in for logged-in
565
# users.
566
def set_index_cache_control_headers(
1✔
567
    headers: wsgiref.headers.Headers, path: str, url: str
568
) -> None:
569
    if DEBUG:
1!
570
        home_path = os.path.join(BASE_DIR, "frontend/out", "index.html")
1✔
571
    else:
572
        home_path = os.path.join(STATIC_ROOT, "index.html")
×
573
    if path == home_path:
1✔
574
        headers["Cache-Control"] = "no-cache, public"
1✔
575

576

577
WHITENOISE_ADD_HEADERS_FUNCTION = set_index_cache_control_headers
1✔
578

579
SITE_ID = 1
1✔
580

581
AUTHENTICATION_BACKENDS = (
1✔
582
    "django.contrib.auth.backends.ModelBackend",
583
    "allauth.account.auth_backends.AuthenticationBackend",
584
)
585

586
SOCIALACCOUNT_PROVIDERS = {
1✔
587
    "fxa": {
588
        # Note: to request "profile" scope, must be a trusted Mozilla client
589
        "SCOPE": ["profile", "https://identity.mozilla.com/account/subscriptions"],
590
        "AUTH_PARAMS": {"access_type": "offline"},
591
        "OAUTH_ENDPOINT": config(
592
            "FXA_OAUTH_ENDPOINT", "https://oauth.accounts.firefox.com/v1"
593
        ),
594
        "PROFILE_ENDPOINT": config(
595
            "FXA_PROFILE_ENDPOINT", "https://profile.accounts.firefox.com/v1"
596
        ),
597
        "VERIFIED_EMAIL": True,  # Assume FxA primary email is verified
598
    }
599
}
600

601
SOCIALACCOUNT_EMAIL_VERIFICATION = "none"
1✔
602
SOCIALACCOUNT_AUTO_SIGNUP = True
1✔
603
SOCIALACCOUNT_LOGIN_ON_GET = True
1✔
604
SOCIALACCOUNT_STORE_TOKENS = True
1✔
605

606
ACCOUNT_ADAPTER = "privaterelay.allauth.AccountAdapter"
1✔
607
ACCOUNT_PRESERVE_USERNAME_CASING = False
1✔
608
ACCOUNT_USERNAME_REQUIRED = False
1✔
609

610
FXA_REQUESTS_TIMEOUT_SECONDS = config("FXA_REQUESTS_TIMEOUT_SECONDS", 1, cast=int)
1✔
611
FXA_SETTINGS_URL = config("FXA_SETTINGS_URL", f"{FXA_BASE_ORIGIN}/settings")
1✔
612
FXA_SUBSCRIPTIONS_URL = config(
1✔
613
    "FXA_SUBSCRIPTIONS_URL", f"{FXA_BASE_ORIGIN}/subscriptions"
614
)
615
# check https://mozilla.github.io/ecosystem-platform/api#tag/Subscriptions/operation/getOauthMozillasubscriptionsCustomerBillingandsubscriptions  # noqa: E501 (line too long)
616
FXA_ACCOUNTS_ENDPOINT = config(
1✔
617
    "FXA_ACCOUNTS_ENDPOINT",
618
    "https://api.accounts.firefox.com/v1",
619
)
620
FXA_SUPPORT_URL = config("FXA_SUPPORT_URL", f"{FXA_BASE_ORIGIN}/support/")
1✔
621

622
LOGGING = {
1✔
623
    "version": 1,
624
    "filters": {
625
        "request_id": {
626
            "()": "dockerflow.logging.RequestIdLogFilter",
627
        },
628
    },
629
    "formatters": {
630
        "json": {
631
            "()": "dockerflow.logging.JsonLogFormatter",
632
            "logger_name": "fx-private-relay",
633
        }
634
    },
635
    "handlers": {
636
        "console_out": {
637
            "level": "DEBUG",
638
            "class": "logging.StreamHandler",
639
            "stream": sys.stdout,
640
            "formatter": "json",
641
            "filters": ["request_id"],
642
        },
643
        "console_err": {
644
            "level": "DEBUG",
645
            "class": "logging.StreamHandler",
646
            "formatter": "json",
647
            "filters": ["request_id"],
648
        },
649
    },
650
    "loggers": {
651
        "root": {
652
            "handlers": ["console_err"],
653
            "level": "WARNING",
654
        },
655
        "request.summary": {
656
            "handlers": ["console_out"],
657
            "level": "DEBUG",
658
            # pytest's caplog fixture requires propagate=True
659
            # outside of pytest, use propagate=False to avoid double logs
660
            "propagate": IN_PYTEST,
661
        },
662
        "events": {
663
            "handlers": ["console_err"],
664
            "level": "WARNING",
665
            "propagate": IN_PYTEST,
666
        },
667
        "eventsinfo": {
668
            "handlers": ["console_out"],
669
            "level": "INFO",
670
            "propagate": IN_PYTEST,
671
        },
672
        "abusemetrics": {
673
            "handlers": ["console_out"],
674
            "level": "INFO",
675
            "propagate": IN_PYTEST,
676
        },
677
        "studymetrics": {
678
            "handlers": ["console_out"],
679
            "level": "INFO",
680
            "propagate": IN_PYTEST,
681
        },
682
        "markus": {
683
            "handlers": ["console_out"],
684
            "level": "DEBUG",
685
            "propagate": IN_PYTEST,
686
        },
687
        GLEAN_EVENT_MOZLOG_TYPE: {
688
            "handlers": ["console_out"],
689
            "level": "DEBUG",
690
            "propagate": IN_PYTEST,
691
        },
692
        "dockerflow": {
693
            "handlers": ["console_err"],
694
            "level": "WARNING",
695
            "propagate": IN_PYTEST,
696
        },
697
    },
698
}
699

700
DRF_RENDERERS = ["rest_framework.renderers.JSONRenderer"]
1✔
701
if DEBUG and not IN_PYTEST:
1!
702
    DRF_RENDERERS += [
×
703
        "rest_framework.renderers.BrowsableAPIRenderer",
704
    ]
705

706
FIRST_EMAIL_RATE_LIMIT = config("FIRST_EMAIL_RATE_LIMIT", "5/minute")
1✔
707
if IN_PYTEST or RELAY_CHANNEL in ["local", "dev"]:
1!
708
    FIRST_EMAIL_RATE_LIMIT = "1000/minute"
1✔
709

710
REST_FRAMEWORK = {
1✔
711
    "DEFAULT_AUTHENTICATION_CLASSES": [
712
        "api.authentication.FxaTokenAuthentication",
713
        "rest_framework.authentication.TokenAuthentication",
714
        "rest_framework.authentication.SessionAuthentication",
715
    ],
716
    "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
717
    "DEFAULT_RENDERER_CLASSES": DRF_RENDERERS,
718
    "DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
719
    "EXCEPTION_HANDLER": "api.views.relay_exception_handler",
720
}
721
if API_DOCS_ENABLED:
1!
722
    REST_FRAMEWORK["DEFAULT_SCHEMA_CLASS"] = "drf_spectacular.openapi.AutoSchema"
1✔
723

724
SPECTACULAR_SETTINGS = {
1✔
725
    "SWAGGER_UI_DIST": "SIDECAR",
726
    "SWAGGER_UI_FAVICON_HREF": "SIDECAR",
727
    "REDOC_DIST": "SIDECAR",
728
    "TITLE": "Firefox Relay API",
729
    "DESCRIPTION": (
730
        "Keep your email safe from hackers and trackers. This API is built with"
731
        " Django REST Framework and powers the Relay website UI, add-on,"
732
        " Firefox browser, and 3rd-party app integrations."
733
    ),
734
    "VERSION": "1.0",
735
    "SERVE_INCLUDE_SCHEMA": False,
736
    "PREPROCESSING_HOOKS": ["api.schema.preprocess_ignore_deprecated_paths"],
737
    "SORT_OPERATIONS": "api.schema.sort_by_tag",
738
}
739

740
if IN_PYTEST or RELAY_CHANNEL in ["local", "dev"]:
1!
741
    _DEFAULT_PHONE_RATE_LIMIT = "1000/minute"
1✔
742
else:
743
    _DEFAULT_PHONE_RATE_LIMIT = "5/minute"
×
744
PHONE_RATE_LIMIT = config("PHONE_RATE_LIMIT", _DEFAULT_PHONE_RATE_LIMIT)
1✔
745

746
# Turn on logging out on GET in development.
747
# This allows `/mock/logout/` in the front-end to clear the
748
# session cookie. Without this, after switching accounts in dev mode,
749
# then logging out again, API requests continue succeeding even without
750
# an auth token:
751
ACCOUNT_LOGOUT_ON_GET = DEBUG
1✔
752

753
# TODO: introduce an environment variable to control CORS_ALLOWED_ORIGINS
754
# https://mozilla-hub.atlassian.net/browse/MPP-3468
755
CORS_URLS_REGEX = r"^/api/"
1✔
756
CORS_ALLOWED_ORIGINS = [
1✔
757
    "https://vault.bitwarden.com",
758
    "https://vault.bitwarden.eu",
759
]
760
if RELAY_CHANNEL in ["dev", "stage"]:
1!
761
    CORS_ALLOWED_ORIGINS += [
×
762
        "https://vault.qa.bitwarden.pw",
763
        "https://vault.euqa.bitwarden.pw",
764
    ]
765
# Allow origins for each environment to help debug cors headers
766
if RELAY_CHANNEL == "local":
1!
767
    # In local dev, next runs on localhost and makes requests to /accounts/
768
    CORS_ALLOWED_ORIGINS += [
1✔
769
        "http://localhost:3000",
770
        "http://0.0.0.0:3000",
771
        "http://127.0.0.1:8000",
772
    ]
773
    CORS_URLS_REGEX = r"^/(api|accounts)/"
1✔
774
if RELAY_CHANNEL == "dev":
1!
775
    CORS_ALLOWED_ORIGINS += [
×
776
        "https://dev.fxprivaterelay.nonprod.cloudops.mozgcp.net",
777
    ]
778
if RELAY_CHANNEL == "stage":
1!
779
    CORS_ALLOWED_ORIGINS += [
×
780
        "https://stage.fxprivaterelay.nonprod.cloudops.mozgcp.net",
781
    ]
782

783
CSRF_TRUSTED_ORIGINS = []
1✔
784
if RELAY_CHANNEL == "local":
1!
785
    # In local development, the React UI can be served up from a different server
786
    # that needs to be allowed to make requests.
787
    # In production, the frontend is served by Django, is therefore on the same
788
    # origin and thus has access to the same cookies.
789
    CORS_ALLOW_CREDENTIALS = True
1✔
790
    SESSION_COOKIE_SAMESITE = None
1✔
791
    CSRF_TRUSTED_ORIGINS += [
1✔
792
        "http://localhost:3000",
793
        "http://0.0.0.0:3000",
794
    ]
795

796
SENTRY_RELEASE = config("SENTRY_RELEASE", "")
1✔
797
CIRCLE_SHA1 = config("CIRCLE_SHA1", "")
1✔
798
CIRCLE_TAG = config("CIRCLE_TAG", "")
1✔
799
CIRCLE_BRANCH = config("CIRCLE_BRANCH", "")
1✔
800

801
sentry_release: str | None = None
1✔
802
if SENTRY_RELEASE:
1!
803
    sentry_release = SENTRY_RELEASE
×
804
elif CIRCLE_TAG and CIRCLE_TAG != "unknown":
1!
805
    sentry_release = CIRCLE_TAG
1✔
UNCOV
806
elif (
×
807
    CIRCLE_SHA1
808
    and CIRCLE_SHA1 != "unknown"
809
    and CIRCLE_BRANCH
810
    and CIRCLE_BRANCH != "unknown"
811
):
UNCOV
812
    sentry_release = f"{CIRCLE_BRANCH}:{CIRCLE_SHA1}"
×
813

814
SENTRY_DEBUG = config("SENTRY_DEBUG", DEBUG, cast=bool)
1✔
815

816
SENTRY_ENVIRONMENT = config("SENTRY_ENVIRONMENT", RELAY_CHANNEL)
1✔
817
# Use "local" as default rather than "prod", to catch ngrok.io URLs
818
if SENTRY_ENVIRONMENT == "prod" and SITE_ORIGIN != "https://relay.firefox.com":
1!
819
    SENTRY_ENVIRONMENT = "local"
×
820

821
sentry_sdk.init(
1✔
822
    dsn=config("SENTRY_DSN", None),
823
    integrations=[DjangoIntegration(cache_spans=not DEBUG)],
824
    debug=SENTRY_DEBUG,
825
    include_local_variables=DEBUG,
826
    release=sentry_release,
827
    environment=SENTRY_ENVIRONMENT,
828
)
829
# Duplicates events for unhandled exceptions, but without useful tracebacks
830
ignore_logger("request.summary")
1✔
831
# Security scanner attempts, no action required
832
# Can be re-enabled when hostname allow list implemented at the load balancer
833
ignore_logger("django.security.DisallowedHost")
1✔
834
# Fluent errors, mostly when a translation is unavailable for the locale.
835
# It is more effective to process these from logs using BigQuery than to track
836
# as events in Sentry.
837
ignore_logger("django_ftl.message_errors")
1✔
838
# Security scanner attempts on Heroku dev, no action required
839
if RELAY_CHANNEL == "dev":
1!
840
    ignore_logger("django.security.SuspiciousFileOperation")
×
841

842

843
_MARKUS_BACKENDS: list[dict[str, Any]] = []
1✔
844
if DJANGO_STATSD_ENABLED:
1!
845
    _MARKUS_BACKENDS.append(
×
846
        {
847
            "class": "markus.backends.datadog.DatadogMetrics",
848
            "options": {
849
                "statsd_host": STATSD_HOST,
850
                "statsd_port": STATSD_PORT,
851
                "statsd_prefix": STATSD_PREFIX,
852
            },
853
        }
854
    )
855
if STATSD_DEBUG:
1!
856
    _MARKUS_BACKENDS.append(
×
857
        {
858
            "class": "markus.backends.logging.LoggingMetrics",
859
            "options": {
860
                "logger_name": "markus",
861
                "leader": "METRICS",
862
            },
863
        }
864
    )
865
markus.configure(backends=_MARKUS_BACKENDS)
1✔
866

867
if USE_SILK:
1!
868
    SILKY_PYTHON_PROFILER = True
×
869
    SILKY_PYTHON_PROFILER_BINARY = True
×
870
    SILKY_PYTHON_PROFILER_RESULT_PATH = ".silk-profiler"
×
871

872
# Settings for manage.py process_emails_from_sqs
873
PROCESS_EMAIL_BATCH_SIZE = config(
1✔
874
    "PROCESS_EMAIL_BATCH_SIZE", 10, cast=Choices(range(1, 11), cast=int)
875
)
876
PROCESS_EMAIL_DELETE_FAILED_MESSAGES = config(
1✔
877
    "PROCESS_EMAIL_DELETE_FAILED_MESSAGES", False, cast=bool
878
)
879
PROCESS_EMAIL_HEALTHCHECK_PATH = config(
1✔
880
    "PROCESS_EMAIL_HEALTHCHECK_PATH", os.path.join(TMP_DIR, "healthcheck.json")
881
)
882
PROCESS_EMAIL_MAX_SECONDS = config("PROCESS_EMAIL_MAX_SECONDS", 0, cast=int) or None
1✔
883
PROCESS_EMAIL_VERBOSITY = config(
1✔
884
    "PROCESS_EMAIL_VERBOSITY", 1, cast=Choices(range(0, 4), cast=int)
885
)
886
PROCESS_EMAIL_VISIBILITY_SECONDS = config(
1✔
887
    "PROCESS_EMAIL_VISIBILITY_SECONDS", 120, cast=int
888
)
889
PROCESS_EMAIL_WAIT_SECONDS = config("PROCESS_EMAIL_WAIT_SECONDS", 5, cast=int)
1✔
890
PROCESS_EMAIL_HEALTHCHECK_MAX_AGE = config(
1✔
891
    "PROCESS_EMAIL_HEALTHCHECK_MAX_AGE", 120, cast=int
892
)
893
PROCESS_EMAIL_MAX_SECONDS_PER_MESSAGE = config(
1✔
894
    "PROCESS_EMAIL_MAX_SECONDS_PER_MESSAGE",
895
    PROCESS_EMAIL_MAX_SECONDS or 120.0,
896
    cast=float,
897
)
898

899
# Django 3.2 switches default to BigAutoField
900
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
1✔
901

902
# python-dockerflow settings
903
DOCKERFLOW_VERSION_CALLBACK = "privaterelay.utils.get_version_info"
1✔
904
DOCKERFLOW_CHECKS = [
1✔
905
    "dockerflow.django.checks.check_database_connected",
906
    "dockerflow.django.checks.check_migrations_applied",
907
]
908
if REDIS_URL:
1!
909
    DOCKERFLOW_CHECKS.append("dockerflow.django.checks.check_redis_connected")
×
910
DOCKERFLOW_REQUEST_ID_HEADER_NAME = config("DOCKERFLOW_REQUEST_ID_HEADER_NAME", None)
1✔
911
SILENCED_SYSTEM_CHECKS = sorted(
1✔
912
    set(config("DJANGO_SILENCED_SYSTEM_CHECKS", default="", cast=Csv()))
913
    | {
914
        # (models.W040) SQLite does not support indexes with non-key columns.
915
        # RelayAddress index idx_ra_created_by_addon uses this for PostgreSQL.
916
        "models.W040",
917
    }
918
)
919

920
# django-ftl settings
921
AUTO_RELOAD_BUNDLES = False  # Requires pyinotify
1✔
922

923
# Patching for django-types
924
django_stubs_ext.monkeypatch()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc