Fix S3 bucket policy delete. Closes #396.
This commit is contained in:
parent
6b2f54604e
commit
323f720cb5
@ -276,6 +276,10 @@ class S3Backend(BaseBackend):
|
||||
def set_bucket_policy(self, bucket_name, policy):
|
||||
self.get_bucket(bucket_name).policy = policy
|
||||
|
||||
def delete_bucket_policy(self, bucket_name, body):
|
||||
bucket = self.get_bucket(bucket_name)
|
||||
bucket.policy = None
|
||||
|
||||
def set_bucket_lifecycle(self, bucket_name, rules):
|
||||
bucket = self.get_bucket(bucket_name)
|
||||
bucket.set_lifecycle(rules)
|
||||
|
@ -59,14 +59,22 @@ class ResponseObject(_TemplateEnvironmentMixin):
|
||||
# If no bucket specified, list all buckets
|
||||
return self.all_buckets()
|
||||
|
||||
if hasattr(request, 'body'):
|
||||
# Boto
|
||||
body = request.body
|
||||
else:
|
||||
# Flask server
|
||||
body = request.data
|
||||
body = body.decode('utf-8')
|
||||
|
||||
if method == 'HEAD':
|
||||
return self._bucket_response_head(bucket_name, headers)
|
||||
elif method == 'GET':
|
||||
return self._bucket_response_get(bucket_name, querystring, headers)
|
||||
elif method == 'PUT':
|
||||
return self._bucket_response_put(request, region_name, bucket_name, querystring, headers)
|
||||
return self._bucket_response_put(body, region_name, bucket_name, querystring, headers)
|
||||
elif method == 'DELETE':
|
||||
return self._bucket_response_delete(bucket_name, querystring, headers)
|
||||
return self._bucket_response_delete(body, bucket_name, querystring, headers)
|
||||
elif method == 'POST':
|
||||
return self._bucket_response_post(request, bucket_name, headers)
|
||||
else:
|
||||
@ -149,15 +157,7 @@ class ResponseObject(_TemplateEnvironmentMixin):
|
||||
result_folders=result_folders
|
||||
)
|
||||
|
||||
def _bucket_response_put(self, request, region_name, bucket_name, querystring, headers):
|
||||
if hasattr(request, 'body'):
|
||||
# Boto
|
||||
body = request.body
|
||||
else:
|
||||
# Flask server
|
||||
body = request.data
|
||||
body = body.decode('utf-8')
|
||||
|
||||
def _bucket_response_put(self, body, region_name, bucket_name, querystring, headers):
|
||||
if 'versioning' in querystring:
|
||||
ver = re.search('<Status>([A-Za-z]+)</Status>', body)
|
||||
if ver:
|
||||
@ -188,8 +188,11 @@ class ResponseObject(_TemplateEnvironmentMixin):
|
||||
template = self.response_template(S3_BUCKET_CREATE_RESPONSE)
|
||||
return 200, headers, template.render(bucket=new_bucket)
|
||||
|
||||
def _bucket_response_delete(self, bucket_name, querystring, headers):
|
||||
if 'lifecycle' in querystring:
|
||||
def _bucket_response_delete(self, body, bucket_name, querystring, headers):
|
||||
if 'policy' in querystring:
|
||||
self.backend.delete_bucket_policy(bucket_name, body)
|
||||
return 204, headers, ""
|
||||
elif 'lifecycle' in querystring:
|
||||
bucket = self.backend.get_bucket(bucket_name)
|
||||
bucket.delete_lifecycle()
|
||||
return 204, headers, ""
|
||||
|
@ -871,6 +871,11 @@ def test_policy():
|
||||
|
||||
bucket.get_policy().decode('utf-8').should.equal(policy)
|
||||
|
||||
bucket.delete_policy()
|
||||
|
||||
with assert_raises(S3ResponseError) as err:
|
||||
bucket.get_policy()
|
||||
|
||||
|
||||
"""
|
||||
boto3
|
||||
|
Loading…
Reference in New Issue
Block a user