From 7719b26e2e89c2fd2be327d47de612cd50135a58 Mon Sep 17 00:00:00 2001 From: James Murty Date: Thu, 16 Mar 2017 11:16:23 +1100 Subject: [PATCH] Use public-read for S3-enabled storage of thumbnails by default When the `ENABLE_S3_MEDIA` setting is applied, continue to use "private" S3 storage for media assets by default, but switch to using "public" S3 storage for thumbnails generated by the thumbnailing system. Here "private" storage means that images are only accessible through time-limited signed S3 URLs, while "public" means that thumbnails will be accessible through non-time-limited standard S3 URLs and the thumbnail images will be stored with the `public-read` ACL behind the scenes. As part of this change, the `S3DefaultStorage` storage class is renamed to `S3DefaultPrivateStorage` to be explicit (the original class name remains available for backwards-compatibility) and the new `S3DefaultPublicStorage` class is added. --- icekit/project/settings/calculated.py | 8 ++++++-- icekit/utils/storage.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/icekit/project/settings/calculated.py b/icekit/project/settings/calculated.py index 03f7b958..91f4df91 100644 --- a/icekit/project/settings/calculated.py +++ b/icekit/project/settings/calculated.py @@ -126,6 +126,10 @@ # STORAGES #################################################################### +# Override media and thumbnail storage if S3 media is enabled if ENABLE_S3_MEDIA: - DEFAULT_FILE_STORAGE = 'icekit.utils.storage.S3DefaultStorage' - THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE + # "Private" S3 storage by default for most media assets + DEFAULT_FILE_STORAGE = 'icekit.utils.storage.S3DefaultPrivateStorage' + + # "Public" S3 storage by default for thumbnails + THUMBNAIL_DEFAULT_STORAGE = 'icekit.utils.storage.S3DefaultPublicStorage' diff --git a/icekit/utils/storage.py b/icekit/utils/storage.py index 9667bd13..087103b7 100644 --- a/icekit/utils/storage.py +++ b/icekit/utils/storage.py @@ -54,7 +54,7 @@ def __init__(self, *args, **kwargs): # STORAGE CLASSES ############################################################# -class S3DefaultStorage( +class S3DefaultPrivateStorage( # HashedMediaMixin, S3MediaLocationMixin, S3PrivateMixin, @@ -63,4 +63,17 @@ class S3DefaultStorage( pass +class S3DefaultPublicStorage( + # HashedMediaMixin, + S3MediaLocationMixin, + S3PublicMixin, + S3Boto3Storage): + + pass + + +# TODO Deprecated, use `S3DefaultPrivateStorage` instead of `S3DefaultStorage` +S3DefaultStorage = S3DefaultPrivateStorage + + default_storage = get_storage_class(settings.DEFAULT_FILE_STORAGE)()