-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.py
1267 lines (1180 loc) · 37.7 KB
/
settings.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
"""
Django settings for ocw_studio.
"""
import logging
import os
import platform
from urllib.parse import urlparse
import dj_database_url
from django.core.exceptions import ImproperlyConfigured
from mitol.common.envs import (
get_bool,
get_delimited_list,
get_features,
get_int,
get_site_name,
get_string,
import_settings_modules,
init_app_settings,
)
from main.constants import PRODUCTION_NAMES
from main.envs import get_list_of_str
from main.sentry import init_sentry
# pylint: disable=too-many-lines
VERSION = "0.134.0"
SITE_ID = get_int(
name="OCW_STUDIO_SITE_ID",
default=1,
description="The default site id for django sites framework",
)
# Sentry
ENVIRONMENT = get_string(
name="OCW_STUDIO_ENVIRONMENT",
default="dev",
description="The execution environment that the app is in (e.g. dev, staging, prod)", # noqa: E501
required=True,
)
# this is only available to heroku review apps
HEROKU_APP_NAME = get_string(
name="HEROKU_APP_NAME", default=None, description="The name of the review app"
)
# initialize Sentry before doing anything else so we capture any config errors
SENTRY_DSN = get_string(
name="SENTRY_DSN", default="", description="The connection settings for Sentry"
)
SENTRY_LOG_LEVEL = get_string(
name="SENTRY_LOG_LEVEL", default="ERROR", description="The log level for Sentry"
)
init_sentry(
dsn=SENTRY_DSN,
environment=ENVIRONMENT,
version=VERSION,
log_level=SENTRY_LOG_LEVEL,
heroku_app_name=HEROKU_APP_NAME,
)
init_app_settings(namespace="OCW_STUDIO", site_name="OCW Studio")
SITE_NAME = get_site_name()
import_settings_modules(
"mitol.common.settings.base",
"mitol.common.settings.webpack",
"mitol.mail.settings.email",
"mitol.authentication.settings.touchstone",
)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname( # noqa: PTH120
os.path.dirname(os.path.abspath(__file__)) # noqa: PTH100, PTH120
)
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = get_string(
name="SECRET_KEY", default=None, description="Django secret key.", required=True
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_bool(
name="DEBUG",
default=False,
dev_only=True,
description="Set to True to enable DEBUG mode. Don't turn on in production.",
)
ALLOWED_HOSTS = ["*"]
SECURE_SSL_REDIRECT = get_bool(
name="OCW_STUDIO_SECURE_SSL_REDIRECT",
default=True,
description="Application-level SSL redirect setting.",
)
USE_X_FORWARDED_HOST = get_bool(
name="USE_X_FORWARDED_HOST",
default=False,
description="Set HOST header to original domain accessed by user",
)
USE_X_FORWARDED_PORT = get_bool(
name="USE_X_FORWARDED_PORT",
default=False,
description="Use the PORT from original url accessed by user",
)
WEBPACK_LOADER = {
"DEFAULT": {
"CACHE": not DEBUG,
"BUNDLE_DIR_NAME": "bundles/",
"STATS_FILE": os.path.join(BASE_DIR, "webpack-stats.json"), # noqa: PTH118
"POLL_INTERVAL": 0.1,
"TIMEOUT": None,
"IGNORE": [r".+\.hot-update\.+", r".+\.js\.map"],
}
}
# configure a custom user model
AUTH_USER_MODEL = "users.User"
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"guardian",
"hijack",
"hijack.contrib.admin",
"safedelete",
# django-robots
"rest_framework",
"social_django",
"robots",
"anymail",
"bulk_update_or_create",
# Put our apps after this point
"main",
"users",
"websites",
"ocw_import",
"news",
"content_sync",
"gdrive_sync",
"videos",
"external_resources",
# common apps, need to be after ocw-studio apps for template overridding
"mitol.common.apps.CommonApp",
"mitol.authentication.apps.AuthenticationApp",
"mitol.mail.apps.MailApp",
]
if ENVIRONMENT not in PRODUCTION_NAMES:
INSTALLED_APPS.append("localdev")
DISABLE_WEBPACK_LOADER_STATS = get_bool(
name="DISABLE_WEBPACK_LOADER_STATS",
default=False,
description="Disabled webpack loader stats",
)
if not DISABLE_WEBPACK_LOADER_STATS:
INSTALLED_APPS.append("webpack_loader")
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.sites.middleware.CurrentSiteMiddleware",
"main.middleware.CachelessAPIMiddleware",
"hijack.middleware.HijackUserMiddleware",
]
# enable the nplusone profiler only in debug mode
if DEBUG:
INSTALLED_APPS.append("nplusone.ext.django")
MIDDLEWARE.append("nplusone.ext.django.NPlusOneMiddleware")
SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies"
LOGIN_REDIRECT_URL = "/"
LOGIN_URL = "/"
LOGIN_ERROR_URL = "/"
ROOT_URLCONF = "main.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [f"{BASE_DIR}/templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "main.wsgi.application"
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DEFAULT_DATABASE_CONFIG = dj_database_url.parse(
get_string(
name="DATABASE_URL",
default=f"sqlite:///{os.path.join(BASE_DIR, 'db.sqlite3')}", # noqa: PTH118
description="The connection url to the Postgres database",
required=True,
write_app_json=False,
)
)
DEFAULT_DATABASE_CONFIG["CONN_MAX_AGE"] = get_int(
name="OCW_STUDIO_DB_CONN_MAX_AGE",
default=0,
description="Maximum age of connection to Postgres in seconds",
)
# If True, disables server-side database cursors to prevent invalid cursor errors when using pgbouncer # noqa: E501
DEFAULT_DATABASE_CONFIG["DISABLE_SERVER_SIDE_CURSORS"] = get_bool(
name="OCW_STUDIO_DB_DISABLE_SS_CURSORS",
default=True,
description="Disables Postgres server side cursors",
)
if get_bool(
name="OCW_STUDIO_DB_DISABLE_SSL",
default=False,
description="Disables SSL to postgres if set to True",
):
DEFAULT_DATABASE_CONFIG["OPTIONS"] = {}
else:
DEFAULT_DATABASE_CONFIG["OPTIONS"] = {"sslmode": "require"}
DATABASES = {"default": DEFAULT_DATABASE_CONFIG}
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# django-robots
ROBOTS_USE_HOST = False
ROBOTS_CACHE_TIMEOUT = get_int(
name="ROBOTS_CACHE_TIMEOUT",
default=60 * 60 * 24,
description="How long the robots.txt file should be cached",
)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
# Serve static files with dj-static
STATIC_URL = "/static/"
STATIC_ROOT = "staticfiles"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),) # noqa: PTH118
# Important to define this so DEBUG works properly
INTERNAL_IPS = (
get_string(
name="HOST_IP", default="127.0.0.1", description="This server's host IP"
),
)
# e-mail configurable admins
ADMIN_EMAIL = get_string(
name="OCW_STUDIO_ADMIN_EMAIL",
default="",
description="E-mail to send 500 reports to.",
)
ADMINS = (("Admins", ADMIN_EMAIL),) if ADMIN_EMAIL != "" else ()
# Logging configuration
LOG_LEVEL = get_string(
name="OCW_STUDIO_LOG_LEVEL", default="INFO", description="The log level default"
)
DJANGO_LOG_LEVEL = get_string(
name="DJANGO_LOG_LEVEL", default="INFO", description="The log level for django"
)
# For logging to a remote syslog host
LOG_HOST = get_string(
name="OCW_STUDIO_LOG_HOST",
default="localhost",
description="Remote syslog server hostname",
)
LOG_HOST_PORT = get_int(
name="OCW_STUDIO_LOG_HOST_PORT",
default=514,
description="Remote syslog server port",
)
HOSTNAME = platform.node().split(".")[0]
# nplusone profiler logger configuration
NPLUSONE_LOGGER = logging.getLogger("nplusone")
NPLUSONE_LOG_LEVEL = logging.ERROR
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
}
},
"formatters": {
"verbose": {
"format": (
"[%(asctime)s] %(levelname)s %(process)d [%(name)s] "
"%(filename)s:%(lineno)d - "
f"[{HOSTNAME}] - %(message)s"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
}
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"syslog": {
"level": LOG_LEVEL,
"class": "logging.handlers.SysLogHandler",
"facility": "local7",
"formatter": "verbose",
"address": (LOG_HOST, LOG_HOST_PORT),
},
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
},
"loggers": {
"django": {
"propagate": True,
"level": DJANGO_LOG_LEVEL,
"handlers": ["console", "syslog"],
},
"django.request": {
"handlers": ["mail_admins"],
"level": DJANGO_LOG_LEVEL,
"propagate": True,
},
"nplusone": {
"handlers": ["console"],
"level": "ERROR",
},
},
"root": {
"handlers": ["console", "syslog"],
"level": LOG_LEVEL,
},
}
# server-status
STATUS_TOKEN = get_string(
name="STATUS_TOKEN", default="", description="Token to access the status API."
)
HEALTH_CHECK = ["CELERY", "REDIS", "POSTGRES"]
GA_TRACKING_ID = get_string(
name="GA_TRACKING_ID", default="", description="Google analytics tracking ID"
)
REACT_GA_DEBUG = get_bool(
name="REACT_GA_DEBUG",
default=False,
dev_only=True,
description="Enable debug for react-ga, development only",
)
MEDIA_ROOT = get_string(
name="MEDIA_ROOT",
default="/var/media/",
description="The root directory for locally stored media. Typically not used.",
)
MEDIA_URL = "/media/"
OCW_STUDIO_USE_S3 = get_bool(
name="OCW_STUDIO_USE_S3",
default=False,
description="Use S3 for storage backend (required on Heroku)",
)
MAX_S3_GET_ITERATIONS = get_int(
name="MAX_S3_GET_ITERATIONS",
default=3,
description="Max retry attempts to get an S3 object",
)
AWS_MAX_CONCURRENT_CONNECTIONS = get_int(
name="AWS_MAX_CONCURRENT_CONNECTIONS",
default=10,
description="The max concurrent connections used by cp and sync AWS CLI commands",
)
AWS_ACCESS_KEY_ID = get_string(
name="AWS_ACCESS_KEY_ID", default=None, description="AWS Access Key for S3 storage."
)
AWS_SECRET_ACCESS_KEY = get_string(
name="AWS_SECRET_ACCESS_KEY",
default=None,
description="AWS Secret Key for S3 storage.",
)
AWS_ARTIFACTS_BUCKET_NAME = get_string(
name="AWS_ARTIFACTS_BUCKET_NAME",
default=None,
description="S3 artifacts bucket name.",
)
AWS_STORAGE_BUCKET_NAME = get_string(
name="AWS_STORAGE_BUCKET_NAME", default=None, description="S3 Bucket name."
)
AWS_PREVIEW_BUCKET_NAME = get_string(
name="AWS_PREVIEW_BUCKET_NAME", default=None, description="S3 preview bucket name."
)
AWS_PUBLISH_BUCKET_NAME = get_string(
name="AWS_PUBLISH_BUCKET_NAME", default=None, description="S3 publish bucket name."
)
AWS_TEST_BUCKET_NAME = get_string(
name="AWS_TEST_BUCKET_NAME", default=None, description="S3 test bucket name."
)
AWS_OFFLINE_PREVIEW_BUCKET_NAME = get_string(
name="AWS_OFFLINE_PREVIEW_BUCKET_NAME",
default=None,
description="S3 offline preview bucket name.",
)
AWS_OFFLINE_PUBLISH_BUCKET_NAME = get_string(
name="AWS_OFFLINE_PUBLISH_BUCKET_NAME",
default=None,
description="S3 offline publish bucket name.",
)
AWS_OFFLINE_TEST_BUCKET_NAME = get_string(
name="AWS_OFFLINE_TEST_BUCKET_NAME",
default=None,
description="S3 offline test bucket name.",
)
AWS_QUERYSTRING_AUTH = get_bool(
name="AWS_QUERYSTRING_AUTH",
default=False,
description="Enables querystring auth for S3 urls",
)
AWS_DEFAULT_ACL = "public-read"
AWS_ACCOUNT_ID = get_string(name="AWS_ACCOUNT_ID", description="AWS Account ID")
AWS_REGION = get_string(
name="AWS_REGION", default="us-east-1", description="AWS Region"
)
AWS_ROLE_NAME = get_string(
name="AWS_ROLE_NAME",
default=None,
description="AWS role name to be used for MediaConvert jobs",
)
# Provide nice validation of the configuration
if OCW_STUDIO_USE_S3 and (
not AWS_ACCESS_KEY_ID or not AWS_SECRET_ACCESS_KEY or not AWS_STORAGE_BUCKET_NAME
):
msg = "You have enabled S3 support, but are missing one of AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or AWS_STORAGE_BUCKET_NAME" # noqa: E501
raise ImproperlyConfigured(msg)
if OCW_STUDIO_USE_S3:
STORAGES = {
"default": {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}
# Google Drive and Video settings
DRIVE_SERVICE_ACCOUNT_CREDS = get_string(
name="DRIVE_SERVICE_ACCOUNT_CREDS",
default=None,
description="The contents of the Service Account credentials JSON to use for Google API auth", # noqa: E501
)
DRIVE_SHARED_ID = get_string(
name="DRIVE_SHARED_ID",
default=None,
description="ID of the Shared Drive (a.k.a. Team Drive). This is equal to the top-level folder ID.", # noqa: E501
)
DRIVE_S3_UPLOAD_PREFIX = get_string(
name="DRIVE_S3_UPLOAD_PREFIX",
default="gdrive_uploads",
description=("Prefix to be used for S3 keys of files uploaded from Google Drive"),
)
DRIVE_UPLOADS_PARENT_FOLDER_ID = get_string(
name="DRIVE_UPLOADS_PARENT_FOLDER_ID",
default=None,
description="Gdrive folder for video uploads",
required=False,
)
OPEN_CATALOG_WEBHOOK_KEY = get_string(
name="OPEN_CATALOG_WEBHOOK_KEY",
default="",
description="Open discussions webhook key",
required=False,
)
OPEN_CATALOG_URLS = get_delimited_list(
name="OPEN_CATALOG_URLS",
default="",
description="Open catalog urls",
required=False,
)
VIDEO_S3_TRANSCODE_PREFIX = get_string(
name="VIDEO_S3_TRANSCODE_PREFIX",
default="aws_mediaconvert_transcodes",
description=(
"Prefix to be used for S3 keys of files transcoded from AWS MediaConvert"
),
)
VIDEO_S3_TRANSCODE_ENDPOINT = get_string(
name="VIDEO_S3_TRANSCODE_ENDPOINT",
default="aws_mediaconvert_transcodes",
description=("Endpoint to be used for AWS MediaConvert"),
)
VIDEO_TRANSCODE_QUEUE = get_string(
name="VIDEO_TRANSCODE_QUEUE",
default="Default",
description=("Name of MediaConvert queue to use for transcoding"),
)
YT_ACCESS_TOKEN = get_string(
name="YT_ACCESS_TOKEN", default="", description="Youtube access token"
)
YT_CATEGORY_ID = get_int(
name="YT_CATEGORY_ID",
default=27,
description="Default video category ID for youtube",
)
YT_CLIENT_ID = get_string(
name="YT_CLIENT_ID", default="", description="Youtube Client ID"
)
YT_CLIENT_SECRET = get_string(
name="YT_CLIENT_SECRET", default="", description="Youtube client secret key"
)
YT_REFRESH_TOKEN = get_string(
name="YT_REFRESH_TOKEN", default="", description="YT_REFRESH_TOKEN"
)
YT_PROJECT_ID = get_string(
name="YT_PROJECT_ID", default="", description="Youtube project ID"
)
YT_STATUS_UPDATE_FREQUENCY = get_int(
name="YT_STATUS_UPDATE_FREQUENCY",
default=60,
description="The frequency to check for status updates on uploaded youtube videos",
)
YT_UPLOAD_FREQUENCY = get_int(
name="YT_UPLOAD_FREQUENCY",
default=60,
description="The frequency to check for videos to upload to Youtube",
)
YT_UPLOAD_LIMIT = get_int(
name="YT_UPLOAD_LIMIT",
default=50,
description="Max Youtube uploads allowed per day",
)
# OCW metadata fields
FIELD_RESOURCETYPE = get_string(
name="FIELD_RESOURCETYPE",
default="resourcetype",
description="The site config metadata field for the resource type",
)
FIELD_METADATA_TITLE = get_string(
name="FIELD_METADATA_TITLE",
default="course_title",
description="The site metadata field for title",
)
# YouTube OCW metadata fields
YT_FIELD_CAPTIONS = get_string(
name="YT_FIELD_CAPTIONS",
default="video_files.video_captions_file",
description="The site config metadata field for the caption url",
)
YT_FIELD_ID = get_string(
name="YT_FIELD_ID",
default="video_metadata.youtube_id",
description="The site config metadata field for YouTube ID",
)
YT_FIELD_DESCRIPTION = get_string(
name="YT_FIELD_DESCRIPTION",
default="video_metadata.youtube_description",
description="The site config metadata field for YouTube description",
)
YT_FIELD_SPEAKERS = get_string(
name="YT_FIELD_SPEAKERS",
default="video_metadata.video_speakers",
description="The site config metadata field for YouTube speakers",
)
YT_FIELD_TAGS = get_string(
name="YT_FIELD_TAGS",
default="video_metadata.video_tags",
description="The site config metadata field for YouTube video tags",
)
YT_FIELD_THUMBNAIL = get_string(
name="YT_FIELD_THUMBNAIL",
default="video_files.video_thumbnail_file",
description="The site config metadata field for YouTube thumbnail url",
)
YT_FIELD_TRANSCRIPT = get_string(
name="YT_FIELD_TRANSCRIPT",
default="video_files.video_transcript_file",
description="The site config metadata field for the transcript url",
)
UPDATE_TAGGED_3PLAY_TRANSCRIPT_FREQUENCY = get_int(
name="UPDATE_TAGGED_3PLAY_TRANSCRIPT_FREQUENCY",
default=3600,
description="The frequency to check for videos tagged as updated in 3play",
)
UPDATE_MISSING_TRANSCRIPT_FREQUENCY = get_int(
name="UPDATE_MISSING_TRANSCRIPT_FREQUENCY",
default=43200,
description="The frequency to check for transcripts for published videos with blank transcripts", # noqa: E501
)
# Publish status settings
PUBLISH_STATUS_WAIT_TIME = get_int(
name="PUBLISH_STATUS_WAIT_TIME",
default=600,
description="Number of seconds to wait for a publish status update before querying for it via api", # noqa: E501
required=False,
)
PUBLISH_STATUS_CUTOFF = get_int(
name="PUBLISH_STATUS_CUTOFF",
default=1800,
description="Number of seconds to wait for a publish build to fail/succeed before assuming it's stuck", # noqa: E501
required=False,
)
PUBLISH_INCOMPLETE_BUILD_STATUS_FREQUENCY = get_int(
name="PUBLISH_INCOMPLETE_BUILD_STATUS_FREQUENCY",
default=1800,
description="Frequency (in seconds) to run a check on potentially stalled publish builds", # noqa: E501
required=False,
)
# Check External Resources settings
CHECK_EXTERNAL_RESOURCE_STATUS_FREQUENCY = get_int(
name="CHECK_EXTERNAL_RESOURCE_STATUS_FREQUENCY",
default=604800,
description="Frequency (in seconds) to check potentially broken external urls",
required=False,
)
CHECK_EXTERNAL_RESOURCE_TASK_ENABLE = get_bool(
name="CHECK_EXTERNAL_RESOURCE_TASK_STATUS",
default=True,
description="Enables celery task to check potentially broken external urls",
required=False,
)
# Celery
REDISCLOUD_URL = get_string(
name="REDISCLOUD_URL", default=None, description="RedisCloud connection url"
)
if REDISCLOUD_URL is not None:
_redis_url = REDISCLOUD_URL
else:
_redis_url = get_string(
name="REDIS_URL", default=None, description="Redis URL for non-production use"
)
REDIS_MAX_CONNECTIONS = get_int(
name="REDIS_MAX_CONNECTIONS",
default=48,
description="Max number of redis connections",
)
DJANGO_REDIS_CLOSE_CONNECTION = True
CELERY_BROKER_URL = get_string(
name="CELERY_BROKER_URL",
default=_redis_url,
description="Where celery should get tasks, default is Redis URL",
)
CELERY_RESULT_BACKEND = get_string(
name="CELERY_RESULT_BACKEND",
default=_redis_url,
description="Where celery should put task results, default is Redis URL",
)
CELERY_TASK_ALWAYS_EAGER = get_bool(
name="CELERY_TASK_ALWAYS_EAGER",
default=False,
dev_only=True,
description="Enables eager execution of celery tasks, development only",
)
CELERY_TASK_EAGER_PROPAGATES = get_bool(
name="CELERY_TASK_EAGER_PROPAGATES",
default=True,
description="Early executed tasks propagate exceptions",
)
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TIMEZONE = "UTC"
CELERY_BEAT_SCHEDULE = {
"update-youtube-statuses": {
"task": "videos.tasks.update_youtube_statuses",
"schedule": YT_STATUS_UPDATE_FREQUENCY,
},
"upload-youtube-videos": {
"task": "videos.tasks.upload_youtube_videos",
"schedule": YT_UPLOAD_FREQUENCY,
},
"update-transcripts-for-updated-videos": {
"task": "videos.tasks.update_transcripts_for_updated_videos",
"schedule": UPDATE_TAGGED_3PLAY_TRANSCRIPT_FREQUENCY,
},
"attempt-to-update-missing-transcripts": {
"task": "videos.tasks.attempt_to_update_missing_transcripts",
"schedule": UPDATE_MISSING_TRANSCRIPT_FREQUENCY,
},
"check_incomplete_publish_build_statuses": {
"task": "content_sync.tasks.check_incomplete_publish_build_statuses",
"schedule": PUBLISH_INCOMPLETE_BUILD_STATUS_FREQUENCY,
},
}
if CHECK_EXTERNAL_RESOURCE_TASK_ENABLE:
CELERY_BEAT_SCHEDULE["check-broken-external-urls"] = {
"task": "external_resources.tasks.check_external_resources_for_breakages",
"schedule": CHECK_EXTERNAL_RESOURCE_STATUS_FREQUENCY,
}
# django cache back-ends
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "local-in-memory-cache",
},
"redis": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": CELERY_BROKER_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {"max_connections": REDIS_MAX_CONNECTIONS},
},
},
}
FEATURES_DEFAULT = get_bool(
name="FEATURES_DEFAULT",
default=False,
dev_only=True,
description="The default value for all feature flags",
)
FEATURES = get_features()
MIDDLEWARE_FEATURE_FLAG_QS_PREFIX = get_string(
name="MIDDLEWARE_FEATURE_FLAG_QS_PREFIX",
default=None,
description="Feature flag middleware querystring prefix",
)
MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME = get_string(
name="MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME",
default="OCW_STUDIO_FEATURE_FLAGS",
description="Feature flag middleware cookie name",
)
MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS = get_int(
name="MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS",
default=60 * 60,
description="Feature flag middleware cookie max age",
)
if MIDDLEWARE_FEATURE_FLAG_QS_PREFIX:
MIDDLEWARE.append(
[
"main.middleware.QueryStringFeatureFlagMiddleware",
"main.middleware.CookieFeatureFlagMiddleware",
]
)
THREEPLAY_API_KEY = get_string(
name="THREEPLAY_API_KEY",
default=None,
description="3play api key",
)
THREEPLAY_CALLBACK_KEY = get_string(
name="THREEPLAY_CALLBACK_KEY",
default=None,
description="3play callback key",
)
THREEPLAY_PROJECT_ID = get_int(
name="THREEPLAY_PROJECT_ID",
default=2,
description="3play project id",
)
S3_TRANSCRIPTS_PREFIX = get_string(
name="S3_TRANSCRIPTS_PREFIX",
default="transcript_files",
description="s3 transcripts subfolder",
)
# django debug toolbar only in debug mode
if DEBUG:
INSTALLED_APPS.append("debug_toolbar")
# it needs to be enabled before other middlewares
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
AUTHENTICATION_BACKENDS = (
"social_core.backends.saml.SAMLAuth",
"django.contrib.auth.backends.ModelBackend", # this is default
"guardian.backends.ObjectPermissionBackend",
)
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
),
"TEST_REQUEST_DEFAULT_FORMAT": "json",
}
HIJACK_LOGIN_REDIRECT_URL = "sites"
HIJACK_LOGOUT_REDIRECT_URL = "/admin/users/user/"
HIJACK_REGISTER_ADMIN = False
HIJACK_ALLOW_GET_REQUESTS = True
LOGOUT_URL = "/logout"
LOGOUT_REDIRECT_URL = "/"
SOCIAL_AUTH_PIPELINE = (
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.auth_allowed",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.user.get_username",
"social_core.pipeline.social_auth.associate_by_email",
"social_core.pipeline.user.create_user",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
)
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "sites"
SOCIAL_AUTH_LOGIN_ERROR_URL = "main-index"
SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS = [
urlparse(SITE_BASE_URL).netloc # pylint: disable=undefined-variable # noqa: F821
]
SOCIAL_AUTH_USER_FIELD_MAPPING = {"fullname": "name"}
# SAML backend settings
SOCIAL_AUTH_SAML_LOGIN_URL = get_string(
name="SOCIAL_AUTH_SAML_LOGIN_URL",
default=None,
description="The URL to redirect the user to for SAML login",
required=True,
)
CONTENT_SYNC_BACKEND = get_string(
name="CONTENT_SYNC_BACKEND",
default=None,
description="The backend to sync websites/content with",
required=False,
)
CONTENT_SYNC_RETRIES = get_int(
name="CONTENT_SYNC_RETRIES",
default=5,
description="Number of times to retry backend sync attempts",
required=False,
)
CONTENT_SYNC_PIPELINE_BACKEND = get_string(
name="CONTENT_SYNC_PIPELINE_BACKEND",
default="concourse",
description="The pipeline backend name to preview/publish websites with",
required=False,
)
# Concourse-CI settings
CONCOURSE_URL = get_string(
name="CONCOURSE_URL",
default=None,
description="The concourse-ci URL",
required=False,
)
CONCOURSE_USERNAME = get_string(
name="CONCOURSE_USERNAME",
default=None,
description="The concourse-ci login username",
required=False,
)
CONCOURSE_PASSWORD = get_string(
name="CONCOURSE_PASSWORD",
default=None,
description="The concourse-ci login password",
required=False,
)
CONCOURSE_TEAM = get_string(
name="CONCOURSE_TEAM",
default="ocw",
description="The concourse-ci team",
required=False,
)
CONCOURSE_HARD_PURGE = get_bool(
name="CONCOURSE_HARD_PURGE",
default=True,
description="Perform a hard purge of the fastly cache",
required=False,
)
CONCOURSE_IS_PRIVATE_REPO = get_bool(
name="CONCOURSE_IS_PRIVATE_REPO",
default=True,
description="True if a git repo requires authentication to retrieve",
required=False,
)
# Git backend settings
GIT_TOKEN = get_string(
name="GIT_TOKEN",
default=None,
description="An authentication token for git commands",
required=False,
)
GITHUB_APP_ID = get_int(
name="GITHUB_APP_ID",
default=None,
description="A github app id to use for Github API authentication",
required=False,
)
GITHUB_APP_PRIVATE_KEY = (
get_string(
name="GITHUB_APP_PRIVATE_KEY",
default="",
description="A github app private key for authentication",
required=False,
)
.encode()
.decode("unicode_escape")
.encode()
)
GIT_ORGANIZATION = get_string(
name="GIT_ORGANIZATION",
default=None,
description="The organization under which repos should be created",
required=False,
)
GIT_BRANCH_MAIN = get_string(
name="GIT_BRANCH_MAIN",
default="main",
description="The default branch for a git repo",
required=False,
)
GIT_BRANCH_PREVIEW = get_string(
name="GIT_BRANCH_PREVIEW",
default="preview",
description="The preview branch for a git repo",
required=False,
)
GIT_BRANCH_RELEASE = get_string(
name="GIT_BRANCH_RELEASE",
default="release",
description="The release branch for a git repo",
required=False,
)
GIT_DEFAULT_USER_NAME = get_string(
name="GIT_DEFAULT_USER_NAME",
default="Anonymous",
description="The name for the default git committer",
required=False,
)
GIT_DEFAULT_USER_EMAIL = get_string(
name="GIT_DEFAULT_USER_EMAIL",
default="[email protected]",
description="The email for the default git committer",
required=False,
)
GIT_API_URL = get_string(
name="GIT_API_URL",
default=None,
description="Base URL of git API",
required=False,
)
GIT_DOMAIN = get_string(
name="GIT_DOMAIN",
default="www.github.com",
description="Base URL of github for site repos",
required=False,
)
GITHUB_WEBHOOK_KEY = get_string(
name="GITHUB_WEBHOOK_KEY",