1 # Copyright © 2018 Amdocs, AT&T, Bell Canada
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 In order to make Django store trusted static files and untrusted media
19 (user-uploaded) files in separate s3 buckets, we must create two different
22 https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/
23 http://www.leehodgkinson.com/blog/my-mezzanine-s3-setup/
27 # FIXME this module never changes so might not need not be kept in a
28 # configmap. Also it is (almost) the same as what we use in em; that does
29 # not use S3BotoStorageMixin.
31 # There is a newer storage based on boto3 but that doesn't support changing
32 # the HOST, as we need to for non-amazon s3 services. It does support an
33 # "endpoint"; setting AWS_S3_ENDPOINT_URL may cause it to work.
34 from storages.backends.s3boto import S3BotoStorage
35 from filebrowser_safe.storage import S3BotoStorageMixin
36 from django.conf import settings
39 # NOTE for some reason, collectstatic uploads to bucket/location but the
40 # urls constructed are domain/location
41 class S3StaticStorage(S3BotoStorage, S3BotoStorageMixin):
42 custom_domain = '%s/%s' % (settings.AWS_S3_HOST, settings.STATIC_BUCKET)
43 bucket_name = settings.STATIC_BUCKET
47 class S3MediaStorage(S3BotoStorage, S3BotoStorageMixin):
48 custom_domain = '%s/%s' % (settings.AWS_S3_HOST, settings.MEDIA_BUCKET)
49 bucket_name = settings.MEDIA_BUCKET