Skip to content

Commit

Permalink
build: swap default file storage _away_ from deprecated lib
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stvstnfrd authored and Agrendalath committed Jul 31, 2023
1 parent 7be5246 commit 96699d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
9 changes: 2 additions & 7 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
12 changes: 4 additions & 8 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 96699d5

Please sign in to comment.