/
base.py
1871 lines (1695 loc) · 63.7 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
"""IMPORTANT: bedrock/settings/__init__.py contains important logic that determines
which site will be served.
"""
import json
import platform
import socket
import struct
import sys
from os.path import abspath
from pathlib import Path
from django.utils.functional import lazy
import markus
import sentry_sdk
from everett.manager import ListOf
from sentry_processor import DesensitizationProcessor
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import ignore_logger
from bedrock.base.config_manager import config
from bedrock.contentful.constants import (
DEFAULT_CONTENT_TYPES as CONTENTFUL_DEFAULT_CONTENT_TYPES,
)
# ROOT path of the project. A pathlib.Path object.
DATA_PATH = config("DATA_PATH", default="data")
ROOT_PATH = Path(__file__).resolve().parents[2]
DATA_PATH = ROOT_PATH / DATA_PATH
ROOT = str(ROOT_PATH)
def path(*args):
return abspath(str(ROOT_PATH.joinpath(*args)))
def data_path(*args):
return abspath(str(DATA_PATH.joinpath(*args)))
# Is this a development-mode deployment where we might have
# extra behaviour/helpers/URLs enabled? (eg, local dev or demo)
# (Don't infer that this specifically means our Dev _deployment_
# - it doesn't. You can use APP_NAME, below, to get that)
DEV = config("DEV", parser=bool, default="false")
# Is this particular deployment running in _production-like_ mode?
# (This will include the Dev and Staging deployments, for instance)
PROD = config("PROD", parser=bool, default="false")
DEBUG = config("DEBUG", parser=bool, default="false")
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": data_path("bedrock.db"),
},
}
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
CACHES = {
"default": {
"BACKEND": "bedrock.base.cache.SimpleDictCache",
"LOCATION": "default",
"TIMEOUT": 600,
"OPTIONS": {
"MAX_ENTRIES": 5000,
"CULL_FREQUENCY": 4, # 1/4 entries deleted if max reached
},
},
}
# in case django-pylibmc is in use
PYLIBMC_MIN_COMPRESS_LEN = 150 * 1024
PYLIBMC_COMPRESS_LEVEL = 1 # zlib.Z_BEST_SPEED
# Logging
LOG_LEVEL = config("LOG_LEVEL", default="INFO")
HAS_SYSLOG = True
SYSLOG_TAG = "http_app_bedrock"
LOGGING_CONFIG = None
# CEF Logging - TODO: remove these if def redundant
CEF_PRODUCT = "Bedrock"
CEF_VENDOR = "Mozilla"
CEF_VERSION = "0"
CEF_DEVICE_VERSION = "0"
# Internationalization.
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = config("TIME_ZONE", default="America/Los_Angeles")
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
USE_TZ = True
USE_ETAGS = config("USE_ETAGS", default=str(not DEBUG), parser=bool)
# just here so Django doesn't complain
TEST_RUNNER = "django.test.runner.DiscoverRunner"
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-US"
# Languages using BiDi (right-to-left) layout. Overrides/extends Django default.
LANGUAGES_BIDI = ["ar", "ar-dz", "fa", "he", "skr", "ur"]
# Tells the product_details module where to find our local JSON files.
# This ultimately controls how LANGUAGES are constructed.
PROD_DETAILS_CACHE_NAME = "product-details"
PROD_DETAILS_CACHE_TIMEOUT = 60 * 15 # 15 min
PROD_DETAILS_STORAGE = config("PROD_DETAILS_STORAGE", default="product_details.storage.PDDatabaseStorage")
# path into which to clone the p-d json repo
PROD_DETAILS_JSON_REPO_PATH = config("PROD_DETAILS_JSON_REPO_PATH", default=data_path("product_details_json"))
PROD_DETAILS_JSON_REPO_URI = config("PROD_DETAILS_JSON_REPO_URI", default="https://github.com/mozilla-releng/product-details.git")
PROD_DETAILS_JSON_REPO_BRANCH = config("PROD_DETAILS_JSON_REPO_BRANCH", default="production")
# path to updated p-d data for testing before loading into DB
PROD_DETAILS_TEST_DIR = str(Path(PROD_DETAILS_JSON_REPO_PATH).joinpath("public", "1.0"))
# Regions defined on the `/locales/` page.
LOCALES_BY_REGION = {
"Americas": ["azz", "cak", "en-CA", "en-US", "es-AR", "es-CL", "es-MX", "gn", "is", "pt-BR", "trs"],
"Asia Pacific": [
"bn",
"hi-IN",
"id",
"ja",
"kk",
"km",
"ko",
"ml",
"mr",
"ms",
"my",
"ne-NP",
"pa-IN",
"si",
"ta",
"te",
"th",
"tl",
"ur",
"vi",
"zh-CN",
"zh-TW",
],
"Europe": [
"an",
"ast",
"be",
"bg",
"br",
"bs",
"ca",
"cs",
"cy",
"da",
"de",
"dsb",
"el",
"en-GB",
"eo",
"es-ES",
"et",
"eu",
"fi",
"fr",
"fy-NL",
"ga-IE",
"gd",
"gl",
"hr",
"hsb",
"hu",
"hy-AM",
"ia",
"it",
"ka",
"lij",
"lt",
"ltg",
"lv",
"mk",
"nb-NO",
"nl",
"nn-NO",
"oc",
"pl",
"pt-PT",
"rm",
"ro",
"ru",
"sco",
"sk",
"sl",
"sq",
"sr",
"sv-SE",
"tr",
"uk",
"uz",
],
"Middle East and Africa": ["ach", "af", "ar", "az", "fa", "ff", "gu-IN", "he", "kab", "kn", "skr", "son", "xh"],
}
# Our accepted production locales are the values from the above, plus an exception.
PROD_LANGUAGES = sorted(sum(LOCALES_BY_REGION.values(), []) + ["ja-JP-mac"])
GITHUB_REPO = "https://github.com/mozilla/bedrock"
# NOTE: This default l10n config is for mozorg.
# In settings/__init__.py we plug in an alternative Pocket-appropriate l10n setup.
# Global L10n files.
FLUENT_DEFAULT_FILES = [
"affiliate",
"banners/firefox-app-store",
"brands",
"download_button",
"footer",
"fxa_form",
"mozorg/about/shared",
"navigation",
"navigation_v2",
"newsletter_form",
"send_to_device",
"sub_navigation",
"ui",
"mozilla-account-promo",
]
FLUENT_DEFAULT_PERCENT_REQUIRED = config("FLUENT_DEFAULT_PERCENT_REQUIRED", default="80", parser=int)
FLUENT_REPO = config("FLUENT_REPO", default="mozmeao/www-l10n")
FLUENT_REPO_URL = f"https://github.com/{FLUENT_REPO}"
FLUENT_REPO_BRANCH = config("FLUENT_REPO_BRANCH", default="master")
FLUENT_REPO_PATH = DATA_PATH / "www-l10n"
# will be something like "<github username>:<github token>"
FLUENT_REPO_AUTH = config("FLUENT_REPO_AUTH", default="")
FLUENT_LOCAL_PATH = ROOT_PATH / "l10n"
FLUENT_L10N_TEAM_REPO = config("FLUENT_L10N_TEAM_REPO", default="mozilla-l10n/www-l10n")
FLUENT_L10N_TEAM_REPO_URL = f"https://github.com/{FLUENT_L10N_TEAM_REPO}"
FLUENT_L10N_TEAM_REPO_BRANCH = config("FLUENT_L10N_TEAM_REPO_BRANCH", default="master")
FLUENT_L10N_TEAM_REPO_PATH = DATA_PATH / "l10n-team"
# 10 seconds during dev and 10 min in prod
FLUENT_CACHE_TIMEOUT = config("FLUENT_CACHE_TIMEOUT", default="10" if DEBUG else "600", parser=int)
# Order matters. first string found wins.
FLUENT_PATHS = [
# local FTL files
FLUENT_LOCAL_PATH,
# remote FTL files from l10n team
FLUENT_REPO_PATH,
]
# These are defined up front, because we need them for more than just Pocket mode, but
# note that they are also swapped in as the Fluent defaults in settings/__init__.py
POCKET_FLUENT_REPO = config(
"POCKET_FLUENT_REPO",
default="mozilla-l10n/pocket-www-l10n",
)
POCKET_FLUENT_REPO_URL = f"https://github.com/{POCKET_FLUENT_REPO}"
POCKET_FLUENT_REPO_PATH = DATA_PATH / "pocket-www-l10n"
POCKET_FLUENT_REPO_BRANCH = config("POCKET_FLUENT_REPO_BRANCH", default="main")
# Templates to exclude from having an "edit this page" link in the footer
# these are typically ones for which most of the content is in the DB
EXCLUDE_EDIT_TEMPLATES = [
"firefox/releases/nightly-notes.html",
"firefox/releases/dev-browser-notes.html",
"firefox/releases/esr-notes.html",
"firefox/releases/beta-notes.html",
"firefox/releases/aurora-notes.html",
"firefox/releases/release-notes.html",
"firefox/releases/notes.html",
"firefox/releases/system_requirements.html",
"mozorg/credits.html",
"mozorg/about/forums.html",
"security/advisory.html",
"security/advisories.html",
"security/product-advisories.html",
"security/known-vulnerabilities.html",
]
IGNORE_LANG_DIRS = [
".git",
"configs",
"metadata",
]
def get_dev_languages():
try:
return [lang.name for lang in FLUENT_REPO_PATH.iterdir() if lang.is_dir() and lang.name not in IGNORE_LANG_DIRS]
except OSError:
# no locale dir
return list(PROD_LANGUAGES)
DEV_LANGUAGES = get_dev_languages()
DEV_LANGUAGES.append("en-US")
# Map short locale names to long, preferred locale names. This
# will be used in urlresolvers to determine the
# best-matching locale from the user's Accept-Language header.
CANONICAL_LOCALES = {
"en": "en-US",
"es": "es-ES",
"ja-jp-mac": "ja",
"no": "nb-NO",
"pt": "pt-BR",
"sv": "sv-SE",
"zh-hant": "zh-TW", # Bug 1263193
"zh-hant-tw": "zh-TW", # Bug 1263193
"zh-hk": "zh-TW", # Bug 1338072
"zh-hant-hk": "zh-TW", # Bug 1338072
}
# Unlocalized pages are usually redirected to the English (en-US) equivalent,
# but sometimes it would be better to offer another locale as fallback. This map
# specifies such cases.
FALLBACK_LOCALES = {
"es-AR": "es-ES",
"es-CL": "es-ES",
"es-MX": "es-ES",
}
def lazy_lang_group():
"""Groups languages with a common prefix into a map keyed on said prefix"""
from django.conf import settings
groups = {}
langs = settings.DEV_LANGUAGES if settings.DEV else settings.PROD_LANGUAGES
for lang in langs:
if "-" in lang:
prefix, _ = lang.split("-", 1)
groups.setdefault(prefix, []).append(lang)
# add any group prefix to the group list if it is also a supported lang
for groupid in groups:
if groupid in langs:
groups[groupid].append(groupid)
# exclude groups with a single member
return {gid: glist for gid, glist in groups.items() if len(glist) > 1}
def lazy_lang_url_map():
from django.conf import settings
langs = settings.DEV_LANGUAGES if settings.DEV else settings.PROD_LANGUAGES
return {i.lower(): i for i in langs}
def lazy_langs():
"""
Override Django's built-in with our native names
Note: Unlike the above lazy methods, this one returns a list of tuples to
match Django's expectations.
"""
from django.conf import settings
from product_details import product_details
langs = DEV_LANGUAGES if settings.DEV else settings.PROD_LANGUAGES
return [(lang.lower(), product_details.languages[lang]["native"]) for lang in langs if lang in product_details.languages]
LANG_GROUPS = lazy(lazy_lang_group, dict)()
LANGUAGE_URL_MAP = lazy(lazy_lang_url_map, dict)()
LANGUAGES = lazy(lazy_langs, list)()
FEED_CACHE = 3900
# 30 min during dev and 10 min in prod
DOTLANG_CACHE = config("DOTLANG_CACHE", default="1800" if DEBUG else "600", parser=int)
# country code for GEO-IP lookup to return in dev mode
DEV_GEO_COUNTRY_CODE = config("DEV_GEO_COUNTRY_CODE", default="US")
# Paths that don't require a locale code in the URL.
# matches the first url component (e.g. mozilla.org/gameon/)
SUPPORTED_NONLOCALES = [
# from redirects.urls
"media",
"static",
"certs",
"images",
"contribute.json",
"credits",
"gameon",
"robots.txt",
".well-known",
"telemetry",
"webmaker",
"contributor-data",
"healthz",
"readiness",
"healthz-cron",
"2004",
"2005",
"2006",
"keymaster",
"microsummaries",
"xbl",
"revision.txt",
"locales",
"sitemap_none.xml",
]
# Paths that can exist either with or without a locale code in the URL.
# Matches the whole URL path
SUPPORTED_LOCALE_IGNORE = ["/sitemap.xml"]
# Pages that we don't want to be indexed by search engines.
# Only impacts sitemap generator. If you need to disallow indexing of
# specific URLs, add them to mozorg/templates/mozorg/robots.txt.
NOINDEX_URLS = [
r"^(404|500)/",
r"^firefox/welcome/",
r"^contribute/(embed|event)/",
r"^firefox/set-as-default/thanks/",
r"^firefox/unsupported/",
r"^firefox/(sms-)?send-to-device-post",
r"^firefox/feedback",
r"^firefox/stub_attribution_code/",
r"^firefox/dedicated-profiles/",
r"^firefox/installer-help/",
r"^firefox/this-browser-comes-highly-recommended/",
r"^firefox/nightly/notes/feed/$",
r"^firefox.*/all/$",
r"^.+/(firstrun|whatsnew)/$",
r"^m/",
r"^newsletter/(confirm|existing|hacks\.mozilla\.org|recovery|updated|fxa-error)/",
r"^newsletter/opt-out-confirmation/",
r"^newsletter/country/success/",
r"^newsletter/newsletter-strings\.json",
r"^products/vpn/invite/waitlist/",
r"^products/monitor/waitlist-plus/",
r"^products/monitor/waitlist-scan/",
r"/system-requirements/$",
r".*/(firstrun|thanks)/$",
r"^readiness/$",
r"^healthz(-cron)?/$",
r"^country-code\.json$",
r"^firefox/browsers/mobile/get-ios/",
# exclude redirects
r"^foundation/annualreport/$",
r"^firefox/notes/$",
r"^teach/$",
r"^about/legal/impressum/$",
r"^security/announce/",
]
# Pages we do want indexed but don't show up in automated URL discovery
# or are only available in a non-default locale
EXTRA_INDEX_URLS = {
"/privacy/firefox-klar/": ["de"],
"/about/legal/impressum/": ["de"],
}
SITEMAPS_REPO = config("SITEMAPS_REPO", default="https://github.com/mozmeao/www-sitemap-generator.git")
SITEMAPS_REPO_BRANCH = config("SITEMAPS_REPO_BRANCH", default="master")
SITEMAPS_PATH = DATA_PATH / "sitemaps"
# Pages that have different URLs for different locales, e.g.
# 'firefox/private-browsing/': {
# 'en-US': '/firefox/features/private-browsing/',
# },
ALT_CANONICAL_PATHS = {}
ALLOWED_HOSTS = config("ALLOWED_HOSTS", parser=ListOf(str), default="www.mozilla.org,www.ipv6.mozilla.org,www.allizom.org")
ALLOWED_CIDR_NETS = config("ALLOWED_CIDR_NETS", default="", parser=ListOf(str))
# The canonical, production URL without a trailing slash
CANONICAL_URL = "https://www.mozilla.org"
# Make this unique, and don't share it with anybody.
SECRET_KEY = config("SECRET_KEY", default="ssssshhhhh")
MEDIA_URL = config("MEDIA_URL", default="/user-media/")
MEDIA_ROOT = config("MEDIA_ROOT", default=path("media"))
STATIC_URL = config("STATIC_URL", default="/media/")
STATIC_ROOT = config("STATIC_ROOT", default=path("static"))
STATICFILES_STORAGE = (
"django.contrib.staticfiles.storage.StaticFilesStorage" if DEBUG else "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
)
STATICFILES_FINDERS = ("django.contrib.staticfiles.finders.FileSystemFinder",)
STATICFILES_DIRS = (path("assets"),)
if DEBUG:
STATICFILES_DIRS += (path("media"),)
def set_whitenoise_headers(headers, path, url):
if "/fonts/" in url:
headers["Cache-Control"] = "public, max-age=604800" # one week
if url.startswith("/.well-known/matrix/"):
headers["Content-Type"] = "application/json"
if url == "/.well-known/apple-app-site-association":
headers["Content-Type"] = "application/json"
WHITENOISE_ADD_HEADERS_FUNCTION = set_whitenoise_headers
WHITENOISE_ROOT = config("WHITENOISE_ROOT", default=path("root_files"))
WHITENOISE_MAX_AGE = 6 * 60 * 60 # 6 hours
PROJECT_MODULE = "bedrock"
def get_app_name(hostname):
"""
Get the app name from the host name.
The hostname in our deployments will be in the form `bedrock-{version}-{type}-{random-ID}`
where {version} is "dev", "stage", or "prod", and {type} is the process type
(e.g. "web" or "clock"). Everywhere else the hostname won't be in this form and
this helper will just return a default string.
"""
if hostname.startswith("bedrock-"):
app_mode = hostname.split("-")[1]
return "bedrock-" + app_mode
return "bedrock"
HOSTNAME = platform.node()
# Prefer APP_NAME from env, but fall back to hostname parsing. TODO: remove get_app_name() usage once fully redundant
APP_NAME = config("APP_NAME", default=get_app_name(HOSTNAME))
CLUSTER_NAME = config("CLUSTER_NAME", default="")
ENABLE_HOSTNAME_MIDDLEWARE = config("ENABLE_HOSTNAME_MIDDLEWARE", default=str(bool(APP_NAME)), parser=bool)
ENABLE_VARY_NOCACHE_MIDDLEWARE = config("ENABLE_VARY_NOCACHE_MIDDLEWARE", default="false", parser=bool)
# set this to enable basic auth for the entire site
# e.g. BASIC_AUTH_CREDS="thedude:thewalrus"
BASIC_AUTH_CREDS = config("BASIC_AUTH_CREDS", default="")
ENABLE_METRICS_VIEW_TIMING_MIDDLEWARE = config("ENABLE_METRICS_VIEW_TIMING_MIDDLEWARE", default="false", parser=bool)
MIDDLEWARE = [
"allow_cidr.middleware.AllowCIDRMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"bedrock.mozorg.middleware.HostnameMiddleware",
"django.middleware.http.ConditionalGetMiddleware",
"corsheaders.middleware.CorsMiddleware",
"bedrock.mozorg.middleware.VaryNoCacheMiddleware",
"bedrock.base.middleware.BasicAuthMiddleware",
# must come before LocaleURLMiddleware
"bedrock.redirects.middleware.RedirectsMiddleware",
"bedrock.base.middleware.LocaleURLMiddleware",
"bedrock.mozorg.middleware.ClacksOverheadMiddleware",
"bedrock.base.middleware.MetricsStatusMiddleware",
"bedrock.base.middleware.MetricsViewTimingMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"bedrock.mozorg.middleware.CacheMiddleware",
]
ENABLE_CSP_MIDDLEWARE = config("ENABLE_CSP_MIDDLEWARE", default="true", parser=bool)
if ENABLE_CSP_MIDDLEWARE:
MIDDLEWARE.append("csp.middleware.CSPMiddleware")
INSTALLED_APPS = [
# Django contrib apps
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.staticfiles",
"django.contrib.messages",
# Third-party apps, patches, fixes
"commonware.response.cookies",
# L10n
"product_details",
# third-party apps
"django_jinja_markdown",
"django_jinja",
"watchman",
# Local apps
"bedrock.base",
"bedrock.firefox",
"bedrock.foundation",
"bedrock.legal",
"bedrock.legal_docs",
"bedrock.mozorg",
"bedrock.newsletter",
"bedrock.press",
"bedrock.privacy",
"bedrock.products",
"bedrock.externalfiles",
"bedrock.pocket",
"bedrock.security",
"bedrock.releasenotes",
"bedrock.contentcards",
"bedrock.contentful",
"bedrock.utils",
"bedrock.wordpress",
"bedrock.sitemaps",
"bedrock.pocketfeed",
"bedrock.careers",
# last so that redirects here will be last
"bedrock.redirects",
# libs
"django_extensions",
"lib.l10n_utils",
]
# Must match the list at CloudFlare if the
# VaryNoCacheMiddleware is enabled. The home
# page is exempt by default.
VARY_NOCACHE_EXEMPT_URL_PREFIXES = (
"/firefox/",
"/contribute/",
"/about/",
"/contact/",
"/newsletter/",
"/privacy/",
"/foundation/",
)
# Sessions
#
# NB: There are no sessions in Bedrock - it's currently stateless.
# Django's messages framework is configured to use cookie storage,
# not session storage - see MESSAGE_STORAGE below
# legacy setting. backward compat.
DISABLE_SSL = config("DISABLE_SSL", default="true", parser=bool)
# SecurityMiddleware settings
SECURE_REFERRER_POLICY = config("SECURE_REFERRER_POLICY", default="strict-origin-when-cross-origin")
SECURE_HSTS_SECONDS = config("SECURE_HSTS_SECONDS", default="0", parser=int)
SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SECURE_BROWSER_XSS_FILTER = config("SECURE_BROWSER_XSS_FILTER", default="true", parser=bool)
SECURE_CONTENT_TYPE_NOSNIFF = config("SECURE_CONTENT_TYPE_NOSNIFF", default="true", parser=bool)
SECURE_SSL_REDIRECT = config("SECURE_SSL_REDIRECT", default=str(not DISABLE_SSL), parser=bool)
SECURE_REDIRECT_EXEMPT = [
r"^readiness/$",
r"^healthz(-cron)?/$",
]
if config("USE_SECURE_PROXY_HEADER", default=str(SECURE_SSL_REDIRECT), parser=bool):
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
STRFTIME_FORMAT_INTERNAL_USE = "%Y-%m-%d %H:%M:%S"
# watchman
WATCHMAN_DISABLE_APM = True
WATCHMAN_CHECKS = (
"watchman.checks.caches",
"watchman.checks.databases",
)
TEMPLATES = [
{
"BACKEND": "django_jinja.jinja2.Jinja2",
"APP_DIRS": True,
"OPTIONS": {
"match_extension": None,
"finalize": lambda x: x if x is not None else "",
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.contrib.messages.context_processors.messages",
"bedrock.base.context_processors.i18n",
"bedrock.base.context_processors.globals",
"bedrock.base.context_processors.geo",
"bedrock.mozorg.context_processors.canonical_path",
"bedrock.mozorg.context_processors.contrib_numbers",
"bedrock.mozorg.context_processors.current_year",
"bedrock.mozorg.context_processors.funnelcake_param",
"bedrock.mozorg.context_processors.facebook_locale",
"bedrock.firefox.context_processors.latest_firefox_versions",
],
"extensions": [
"jinja2.ext.do",
"jinja2.ext.i18n",
"jinja2.ext.loopcontrols",
"django_jinja.builtins.extensions.CsrfExtension",
"django_jinja.builtins.extensions.StaticFilesExtension",
"django_jinja.builtins.extensions.DjangoFiltersExtension",
"django_jinja_markdown.extensions.MarkdownExtension",
],
},
},
]
# use the Wordpress JSON REST API to get blog data
WP_BLOGS = {
# 'firefox': {
# 'url': 'https://blog.mozilla.org/firefox/',
# 'name': 'The Firefox Frontier',
# default num_posts is 20
# uncomment and change this to get more
# 'num_posts': 20,
# },
"careers": {
"url": "https://blog.mozilla.org/careers/",
"name": "Life@Mozilla",
"num_posts": 20,
},
}
GREENHOUSE_BOARD = config("GREENHOUSE_BOARD", default="mozilla")
# used to connect to @MozillaHQ Pocket account
POCKET_API_URL = config("POCKET_API_URL", default="https://getpocket.com/v3/firefox/profile-recs")
POCKET_CONSUMER_KEY = config("POCKET_CONSUMER_KEY", default="")
POCKET_ACCESS_TOKEN = config("POCKET_ACCESS_TOKEN", default="")
# Todo: move this into Pocket-only settings in a way that can also be accessed in tests
BRAZE_API_URL_BASE = config("BRAZE_API_URL_BASE", default="https://rest.iad-05.braze.com")
BRAZE_API_KEY = config("BRAZE_API_KEY", default="")
BRAZE_API_NEWSLETTERS = {
"news": config("BRAZE_API_NEWSLETTER_ID_NEWS", default=""),
"hits": config("BRAZE_API_NEWSLETTER_ID_HITS", default=""),
}
BRAZE_POCKET_COOKIE_NAME = config("BRAZE_POCKET_COOKIE_NAME", default="a95b4b6")
# Contribute numbers
# TODO: automate these
CONTRIBUTE_NUMBERS = {
"num_mozillians": 10554,
"num_languages": 87,
}
BASKET_URL = config("BASKET_URL", default="https://basket.mozilla.org")
BASKET_API_KEY = config("BASKET_API_KEY", default="")
BASKET_TIMEOUT = config("BASKET_TIMEOUT", parser=int, default="10")
BASKET_SUBSCRIBE_URL = BASKET_URL + "/news/subscribe/"
BOUNCER_URL = config("BOUNCER_URL", default="https://download.mozilla.org/")
# reCAPTCHA keys
RECAPTCHA_PUBLIC_KEY = config("RECAPTCHA_PUBLIC_KEY", default="")
RECAPTCHA_PRIVATE_KEY = config("RECAPTCHA_PRIVATE_KEY", default="")
RECAPTCHA_USE_SSL = config("RECAPTCHA_USE_SSL", parser=bool, default="true")
# Use a message storage mechanism that doesn't need a database.
# This can be changed to use session once we do add a database.
MESSAGE_STORAGE = "django.contrib.messages.storage.cookie.CookieStorage"
default_email_backend = "django.core.mail.backends.console.EmailBackend" if DEBUG else "django.core.mail.backends.smtp.EmailBackend"
EMAIL_BACKEND = config("EMAIL_BACKEND", default=default_email_backend)
EMAIL_HOST = config("EMAIL_HOST", default="localhost")
EMAIL_PORT = config("EMAIL_PORT", default="25", parser=int)
EMAIL_USE_TLS = config("EMAIL_USE_TLS", default="false", parser=bool)
EMAIL_SUBJECT_PREFIX = config("EMAIL_SUBJECT_PREFIX", default="[bedrock] ")
EMAIL_HOST_USER = config("EMAIL_HOST_USER", default="")
EMAIL_HOST_PASSWORD = config("EMAIL_HOST_PASSWORD", default="")
EXTERNAL_FILES_PATH = config("EXTERNAL_FILES_PATH", default=data_path("community_data"))
EXTERNAL_FILES_BRANCH = config("EXTERNAL_FILES_BRANCH", default="master")
EXTERNAL_FILES_REPO = config("EXTERNAL_FILES_REPO", default="https://github.com/mozilla/community-data.git")
EXTERNAL_FILES = {
"credits": {
"type": "bedrock.mozorg.credits.CreditsFile",
"name": "credits/names.csv",
},
}
# Facebook Like button supported locales
# https://www.facebook.com/translations/FacebookLocales.xml
FACEBOOK_LIKE_LOCALES = [
"af_ZA",
"ar_AR",
"az_AZ",
"be_BY",
"bg_BG",
"bn_IN",
"bs_BA",
"ca_ES",
"cs_CZ",
"cy_GB",
"da_DK",
"de_DE",
"el_GR",
"en_GB",
"en_PI",
"en_UD",
"en_US",
"eo_EO",
"es_ES",
"es_LA",
"et_EE",
"eu_ES",
"fa_IR",
"fb_LT",
"fi_FI",
"fo_FO",
"fr_CA",
"fr_FR",
"fy_NL",
"ga_IE",
"gl_ES",
"he_IL",
"hi_IN",
"hr_HR",
"hu_HU",
"hy_AM",
"id_ID",
"is_IS",
"it_IT",
"ja_JP",
"ka_GE",
"km_KH",
"ko_KR",
"ku_TR",
"la_VA",
"lt_LT",
"lv_LV",
"mk_MK",
"ml_IN",
"ms_MY",
"nb_NO",
"ne_NP",
"nl_NL",
"nn_NO",
"pa_IN",
"pl_PL",
"ps_AF",
"pt_BR",
"pt_PT",
"ro_RO",
"ru_RU",
"sk_SK",
"sl_SI",
"sq_AL",
"sr_RS",
"sv_SE",
"sw_KE",
"ta_IN",
"te_IN",
"th_TH",
"tl_PH",
"tr_TR",
"uk_UA",
"vi_VN",
"zh_CN",
"zh_HK",
"zh_TW",
]
# Prefix for media. No trailing slash.
# e.g. '//mozorg.cdn.mozilla.net'
CDN_BASE_URL = config("CDN_BASE_URL", default="")
# newsletters that always show for FxA holders
FXA_NEWSLETTERS = [
"firefox-accounts-journey",
"test-pilot",
"take-action-for-the-internet",
"knowledge-is-power",
]
FXA_NEWSLETTERS_LOCALES = ["en", "de", "fr"]
# Regional press blogs map to locales
PRESS_BLOG_ROOT = "https://blog.mozilla.org/"
PRESS_BLOGS = {
"de": "press-de/",
"en-GB": "press-uk/",
"en-US": "press/",
"es-AR": "press-es/",
"es-CL": "press-es/",
"es-ES": "press-es/",
"es-MX": "press-es/",
"fr": "press-fr/",
"it": "press-it/",
"pl": "press-pl/",
"pt-BR": "press-br/",
}
DONATE_LINK = "https://foundation.mozilla.org/?form=donate&c_id=7014x000000eQOH&utm_source=mozilla.org&utm_medium=referral&utm_campaign=moco{content}"
# Official Firefox Twitter accounts
FIREFOX_TWITTER_ACCOUNTS = {
"en-US": "https://twitter.com/firefox",
"es-ES": "https://twitter.com/firefox_es",
"pt-BR": "https://twitter.com/firefoxbrasil",
}
# Official Mozilla Twitter accounts
MOZILLA_TWITTER_ACCOUNTS = {
"en-US": "https://twitter.com/mozilla",
"de": "https://twitter.com/mozilla_germany",
"fr": "https://twitter.com/mozilla_france",
}
# Official Firefox Instagram accounts
MOZILLA_INSTAGRAM_ACCOUNTS = {
"en-US": "https://www.instagram.com/mozilla/",
"de": "https://www.instagram.com/mozilla_deutschland/",
}
# Mozilla accounts product links
# ***This URL *MUST* end in a traling slash!***
FXA_ENDPOINT = config("FXA_ENDPOINT", default="https://accounts.stage.mozaws.net/" if DEV else "https://accounts.firefox.com/")
# Affiliate micro service (CJMS) endpoint (issue 11212)
CJMS_AFFILIATE_ENDPOINT = "https://stage.cjms.nonprod.cloudops.mozgcp.net/aic" if DEV else "https://cjms.services.mozilla.com/aic"
# Google Play and Apple App Store settings
from .appstores import ( # noqa: E402, F401
AMAZON_FIREFOX_FIRE_TV_LINK,
APPLE_APPSTORE_COUNTRY_MAP,
APPLE_APPSTORE_FIREFOX_LINK,
APPLE_APPSTORE_FOCUS_LINK,
APPLE_APPSTORE_KLAR_LINK,
APPLE_APPSTORE_POCKET_LINK,
GOOGLE_PLAY_FIREFOX_BETA_LINK,
GOOGLE_PLAY_FIREFOX_LINK,
GOOGLE_PLAY_FIREFOX_LINK_MOZILLAONLINE,
GOOGLE_PLAY_FIREFOX_LINK_UTMS,
GOOGLE_PLAY_FIREFOX_NIGHTLY_LINK,
GOOGLE_PLAY_FIREFOX_SEND_LINK,
GOOGLE_PLAY_FOCUS_LINK,
GOOGLE_PLAY_KLAR_LINK,
GOOGLE_PLAY_POCKET_LINK,
)
# Locales that should display the 'Send to Device' widget
SEND_TO_DEVICE_LOCALES = ["de", "en-GB", "en-US", "es-AR", "es-CL", "es-ES", "es-MX", "fr", "id", "pl", "pt-BR", "ru", "zh-TW"]
SEND_TO_DEVICE_MESSAGE_SETS = {
"default": {
"email": {
"android": "download-firefox-android",
"ios": "download-firefox-ios",
"all": "download-firefox-mobile",
}
},
"fx-android": {
"email": {
"android": "get-android-embed",
"ios": "download-firefox-ios",
"all": "download-firefox-mobile",
}
},
"fx-mobile-download-desktop": {
"email": {
"all": "download-firefox-mobile-reco",
}
},
"fx-whatsnew": {
"email": {
"all": "download-firefox-mobile-whatsnew",
}
},
"fx-focus": {
"email": {
"all": "download-focus-mobile-whatsnew",
}
},
"fx-klar": {
"email": {
"all": "download-klar-mobile-whatsnew",
}
},
"download-firefox-rocket": {
"email": {
"all": "download-firefox-rocket",
}
},
"firefox-mobile-welcome": {
"email": {
"all": "firefox-mobile-welcome",
}
},
"lockwise-welcome-download": {
"email": {
"all": "lockwise-welcome-download",
}
},
}
if DEV:
content_cards_default_branch = "dev-processed"
else:
content_cards_default_branch = "prod-processed"
CONTENT_CARDS_PATH = config("CONTENT_CARDS_PATH", default=data_path("content_cards"))
CONTENT_CARDS_REPO = config("CONTENT_CARDS_REPO", default="https://github.com/mozmeao/www-admin.git")