vvp -- VNF Validation Platform
[oom.git] / kubernetes / vvp / charts / vvp-em-uwsgi / resources / config / em / storage.py
1 # Copyright © 2018 Amdocs, AT&T, Bell Canada
2 #
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
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 """
16 storage.py
17
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
20 storage classes.
21
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/
24
25 """
26
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 cms.
29
30 # There is a newer storage based on boto3 but that doesn't support changing
31 # the HOST, as we need to for non-amazon s3 services. It does support an
32 # "endpoint"; setting AWS_S3_ENDPOINT_URL may cause it to work.
33 from storages.backends.s3boto import S3BotoStorage
34 from django.conf import settings
35
36
37 # NOTE for some reason, collectstatic uploads to bucket/location but the
38 # urls constructed are domain/location
39 class S3StaticStorage(S3BotoStorage):
40     custom_domain = '%s/%s' % (settings.AWS_S3_HOST, settings.STATIC_BUCKET)
41     bucket_name = settings.STATIC_BUCKET
42     # location = ...
43
44
45 class S3MediaStorage(S3BotoStorage):
46     custom_domain = '%s/%s' % (settings.AWS_S3_HOST, settings.MEDIA_BUCKET)
47     bucket_name = settings.MEDIA_BUCKET
48     # location = ...