From 96699d577c02e1a45225c26a8959f3e14e92aa5c Mon Sep 17 00:00:00 2001 From: stv Date: Tue, 4 Jul 2023 13:28:57 -0600 Subject: [PATCH] build: swap default file storage _away_ from deprecated lib The S3BotoStorage backend was deprecated in favor of the S3Boto3Storage backend. This change updates the default backend to use the latter. style: This re-links and rewords a relevant comment that had been disconnected during previous refactoring. docs: https://github.com/jschneier/django-storages/blob/ade79308a3f20480bec8a964bdbf2f4e0b50ff43/docs/backends/amazon-S3.rst#migrating-from-boto-to-boto3 Fixes: FAL-3431 Fixes: public-engineering/128 --- cms/envs/common.py | 9 ++------- cms/envs/production.py | 1 + lms/envs/common.py | 12 ++++-------- lms/envs/production.py | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 12b982d95d9b..579b11af410f 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -733,11 +733,6 @@ DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0] #################################### AWS ####################################### -# S3BotoStorage insists on a timeout for uploaded assets. We should make it -# permanent instead, but rather than trying to figure out exactly where that -# setting is, I'm just bumping the expiration time to something absurd (100 -# years). This is only used if DEFAULT_FILE_STORAGE is overriden to use S3 -# in the global settings.py AWS_SES_REGION_NAME = 'us-east-1' AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com' AWS_ACCESS_KEY_ID = None @@ -2461,7 +2456,7 @@ VIDEO_IMAGE_MAX_BYTES=2 * 1024 * 1024, # 2 MB VIDEO_IMAGE_MIN_BYTES=2 * 1024, # 2 KB # Backend storage - # STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage', + # STORAGE_CLASS='storages.backends.s3boto3.S3Boto3Storage', # STORAGE_KWARGS=dict(bucket='video-image-bucket'), STORAGE_KWARGS=dict( location=MEDIA_ROOT, @@ -2476,7 +2471,7 @@ VIDEO_TRANSCRIPTS_SETTINGS = dict( VIDEO_TRANSCRIPTS_MAX_BYTES=3 * 1024 * 1024, # 3 MB # Backend storage - # STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage', + # STORAGE_CLASS='storages.backends.s3boto3.S3Boto3Storage', # STORAGE_KWARGS=dict(bucket='video-transcripts-bucket'), STORAGE_KWARGS=dict( location=MEDIA_ROOT, diff --git a/cms/envs/production.py b/cms/envs/production.py index 92e14799b9fb..9acdd9748e13 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -332,6 +332,7 @@ def get_env_setting(setting): AWS_DEFAULT_ACL = 'private' AWS_BUCKET_ACL = AWS_DEFAULT_ACL +# The number of seconds that a generated URL is valid for. AWS_QUERYSTRING_EXPIRE = 7 * 24 * 60 * 60 # 7 days AWS_S3_CUSTOM_DOMAIN = AUTH_TOKENS.get('AWS_S3_CUSTOM_DOMAIN', 'edxuploads.s3.amazonaws.com') diff --git a/lms/envs/common.py b/lms/envs/common.py index 5cd3a0c06c2d..dcca231fa958 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1952,11 +1952,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring 'conventions/internationalization/i18n_translators_guide.html' #################################### AWS ####################################### -# S3BotoStorage insists on a timeout for uploaded assets. We should make it -# permanent instead, but rather than trying to figure out exactly where that -# setting is, I'm just bumping the expiration time to something absurd (100 -# years). This is only used if DEFAULT_FILE_STORAGE is overriden to use S3 -# in the global settings.py +# The number of seconds that a generated URL is valid for. AWS_QUERYSTRING_EXPIRE = 10 * 365 * 24 * 60 * 60 # 10 years AWS_SES_REGION_NAME = 'us-east-1' AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com' @@ -3772,7 +3768,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring VIDEO_IMAGE_MAX_BYTES=2 * 1024 * 1024, # 2 MB VIDEO_IMAGE_MIN_BYTES=2 * 1024, # 2 KB # Backend storage - # STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage', + # STORAGE_CLASS='storages.backends.s3boto3.S3Boto3Storage', # STORAGE_KWARGS=dict(bucket='video-image-bucket'), STORAGE_KWARGS=dict( location=MEDIA_ROOT, @@ -3788,7 +3784,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring VIDEO_TRANSCRIPTS_SETTINGS = dict( VIDEO_TRANSCRIPTS_MAX_BYTES=3 * 1024 * 1024, # 3 MB # Backend storage - # STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage', + # STORAGE_CLASS='storages.backends.s3boto3.S3Boto3Storage', # STORAGE_KWARGS=dict(bucket='video-transcripts-bucket'), STORAGE_KWARGS=dict( location=MEDIA_ROOT, @@ -5129,7 +5125,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring # See `blockstore.apps.bundles.storage.LongLivedSignedUrlStorage` for details. BUNDLE_ASSET_STORAGE_SETTINGS = dict( # Backend storage - # STORAGE_CLASS='storages.backends.s3boto.S3BotoStorage', + # STORAGE_CLASS='storages.backends.s3boto3.S3Boto3Storage', # STORAGE_KWARGS=dict(bucket='bundle-asset-bucket', location='/path-to-bundles/'), STORAGE_CLASS='django.core.files.storage.FileSystemStorage', STORAGE_KWARGS=dict( diff --git a/lms/envs/production.py b/lms/envs/production.py index d627171e326c..2a4df6657b97 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -463,7 +463,7 @@ def get_env_setting(setting): if AUTH_TOKENS.get('DEFAULT_FILE_STORAGE'): DEFAULT_FILE_STORAGE = AUTH_TOKENS.get('DEFAULT_FILE_STORAGE') elif AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY: - DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' + DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' else: DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'