Skip to content

Commit

Permalink
Warn about upcoming settings change; undo previous commit implementin…
Browse files Browse the repository at this point in the history
…g change
  • Loading branch information
jcushman committed Jul 18, 2018
1 parent 9b62b73 commit cf3f374
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import os
import posixpath
import threading
import warnings
from gzip import GzipFile
from tempfile import SpooledTemporaryFile

from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
from django.core.files.base import File
from django.core.files.storage import Storage
Expand Down Expand Up @@ -195,8 +197,8 @@ class S3Boto3Storage(Storage):
object_parameters = setting('AWS_S3_OBJECT_PARAMETERS', {})
bucket_name = setting('AWS_STORAGE_BUCKET_NAME')
auto_create_bucket = setting('AWS_AUTO_CREATE_BUCKET', False)
default_acl = setting('AWS_DEFAULT_ACL', None)
bucket_acl = setting('AWS_BUCKET_ACL', None)
default_acl = setting('AWS_DEFAULT_ACL', 'public-read')
bucket_acl = setting('AWS_BUCKET_ACL', default_acl)
querystring_auth = setting('AWS_QUERYSTRING_AUTH', True)
querystring_expire = setting('AWS_QUERYSTRING_EXPIRE', 3600)
signature_version = setting('AWS_S3_SIGNATURE_VERSION')
Expand Down Expand Up @@ -259,6 +261,15 @@ def __init__(self, acl=None, bucket=None, **settings):
self.config = Config(s3={'addressing_style': self.addressing_style},
signature_version=self.signature_version)

# warn about upcoming change in default AWS_DEFAULT_ACL setting
if not hasattr(django_settings, 'AWS_DEFAULT_ACL'):
warnings.warn(
"The behavior of S3Boto3Storage will change in django-storages 2.0. "
"To opt into the new behavior now, set AWS_DEFAULT_ACL=None, "
"meaning that saved files will use the default bucket permissions. "
"To preserve the existing behavior, set AWS_DEFAULT_ACL='public-read', "
"meaning that saved files will be globally readable regardless of the default bucket permissions.")

@property
def connection(self):
# TODO: Support host, port like in s3boto
Expand Down
6 changes: 6 additions & 0 deletions tests/test_s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_storage_save(self):
content.file,
ExtraArgs={
'ContentType': 'text/plain',
'ACL': self.storage.default_acl,
}
)

Expand Down Expand Up @@ -123,6 +124,7 @@ def test_content_type(self):
content.file,
ExtraArgs={
'ContentType': 'image/jpeg',
'ACL': self.storage.default_acl,
}
)

Expand All @@ -139,6 +141,7 @@ def test_storage_save_gzipped(self):
ExtraArgs={
'ContentType': 'application/octet-stream',
'ContentEncoding': 'gzip',
'ACL': self.storage.default_acl,
}
)

Expand All @@ -156,6 +159,7 @@ def test_storage_save_gzip(self):
ExtraArgs={
'ContentType': 'text/css',
'ContentEncoding': 'gzip',
'ACL': self.storage.default_acl,
}
)
args, kwargs = obj.upload_fileobj.call_args
Expand Down Expand Up @@ -183,6 +187,7 @@ def test_storage_save_gzip_twice(self):
ExtraArgs={
'ContentType': 'text/css',
'ContentEncoding': 'gzip',
'ACL': self.storage.default_acl,
}
)
args, kwargs = obj.upload_fileobj.call_args
Expand Down Expand Up @@ -246,6 +251,7 @@ def test_auto_creating_bucket(self):
'head_bucket')
self.storage._get_or_create_bucket('testbucketname')
Bucket.create.assert_called_once_with(
ACL='public-read',
CreateBucketConfiguration={
'LocationConstraint': 'sa-east-1',
}
Expand Down

0 comments on commit cf3f374

Please sign in to comment.