Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s3_object - Be more defensive when checking the results of get_bucket…
Browse files Browse the repository at this point in the history
…_ownership_controls (ansible-collections#1117)

s3_object - Be more defensive when checking the results of get_bucket_ownership_controls

SUMMARY
Scaleway have half-implemented get_bucket_ownership_controls, but don't return any rules.  Be a little more defensive when checking the return value of get_bucket_ownership_controls.  The API doesn't strictly say a Rule will always be returned.
Fixes: ansible-collections#1115
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
s3_object
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
tremble authored Oct 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ffd06e9 commit 0c3239b
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1115-s3_object-scaleway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- s3_object - be more defensive when checking the results of ``s3.get_bucket_ownership_controls`` (https://github.com/ansible-collections/amazon.aws/issues/1115).
8 changes: 5 additions & 3 deletions plugins/modules/s3_object.py
Original file line number Diff line number Diff line change
@@ -1083,9 +1083,11 @@ def main():
exists = bucket_check(module, s3, bucket)
if exists:
try:
object_ownership = s3.get_bucket_ownership_controls(Bucket=bucket)['OwnershipControls']['Rules'][0]['ObjectOwnership']
if object_ownership == 'BucketOwnerEnforced':
acl_disabled = True
ownership_controls = s3.get_bucket_ownership_controls(Bucket=bucket)['OwnershipControls']
if ownership_controls.get('Rules'):
object_ownership = ownership_controls['Rules'][0]['ObjectOwnership']
if object_ownership == 'BucketOwnerEnforced':
acl_disabled = True
# if bucket ownership controls are not found
except botocore.exceptions.ClientError:
pass

0 comments on commit 0c3239b

Please sign in to comment.