Skip to content

Commit

Permalink
Add option to prevent setting bucket policy.
Browse files Browse the repository at this point in the history
  • Loading branch information
virtosubogdan committed Mar 25, 2016
1 parent dfb9d8e commit 6e6ebc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 6e6ebc3

Please sign in to comment.