Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to prevent setting bucket policy. #66

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flask_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _upload_files(s3, app, files_, bucket, hashes=None):

def create_all(app, user=None, password=None, bucket_name=None,
location=None, include_hidden=False,
filepath_filter_regex=None):
filepath_filter_regex=None, put_bucket_acl=True):
"""
Uploads of the static assets associated with a Flask application to
Amazon S3.
Expand Down Expand Up @@ -348,6 +348,10 @@ def create_all(app, user=None, password=None, bucket_name=None,
store, set to r'^css'.
:type filepath_filter_regex: `basestring` or None

:param put_bucket_acl: by default Flask-S3 will set the bucket ACL
to public. Set this to false to leave the policy unchanged.
:type put_bucket_acl: `bool`

.. _bucket restrictions: http://docs.amazonwebservices.com/AmazonS3\
/latest/dev/BucketRestrictions.html

Expand Down Expand Up @@ -380,7 +384,8 @@ def create_all(app, user=None, password=None, bucket_name=None,
else:
raise

s3.put_bucket_acl(Bucket=bucket_name, ACL='public-read')
if put_bucket_acl:
s3.put_bucket_acl(Bucket=bucket_name, ACL='public-read')

if app.config['FLASKS3_ONLY_MODIFIED']:
try:
Expand Down
6 changes: 6 additions & 0 deletions test_flask_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ def test_static_folder_path(self):
for i, e in zip(inputs, expected):
self.assertEquals(e, flask_s3._static_folder_path(*i))

@patch('flask_s3.boto3')
def test__bucket_acl_not_set(self, mock_boto3):
flask_s3.create_all(self.app, put_bucket_acl=False)
self.assertFalse(mock_boto3.client().put_bucket_acl.called,
"put_bucket_acl was called!")

@patch('flask_s3._write_files')
def test__upload_uses_prefix(self, mock_write_files):
s3_mock = Mock()
Expand Down