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

[PR #2206/e7db6925 backport][stable-8] s3_object - Add support for expcted_bucket_owner option #2250

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- s3_object - Add support for ``expected_bucket_owner`` option (https://github.com/ansible-collections/amazon.aws/issues/2114).
22 changes: 16 additions & 6 deletions plugins/modules/s3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
type: bool
version_added: 3.1.0
default: True
expected_bucket_owner:
description:
- The account ID of the expected bucket owner.
- If the account ID that you provide does not match the actual owner of the bucket,
the request fails with the HTTP status code 403 Forbidden (access denied).
type: str
version_added: 8.2.0
author:
- "Lester Wade (@lwade)"
- "Sloane Hertel (@s-hertel)"
Expand Down Expand Up @@ -862,13 +869,15 @@ def put_download_url(s3, bucket, obj, expiry):


def get_current_object_tags_dict(module, s3, bucket, obj, version=None):
params = {"Bucket": bucket, "Key": obj}

if module.params.get("expected_bucket_owner"):
params["ExpectedBucketOwner"] = module.params["expected_bucket_owner"]
if version:
params["VersionId"] = version

try:
if version:
current_tags = s3.get_object_tagging(aws_retry=True, Bucket=bucket, Key=obj, VersionId=version).get(
"TagSet"
)
else:
current_tags = s3.get_object_tagging(aws_retry=True, Bucket=bucket, Key=obj).get("TagSet")
current_tags = s3.get_object_tagging(aws_retry=True, **params).get("TagSet")
except is_boto3_error_code(IGNORE_S3_DROP_IN_EXCEPTIONS):
module.warn("GetObjectTagging is not implemented by your storage provider.")
return {}
Expand Down Expand Up @@ -1508,6 +1517,7 @@ def main():
),
),
validate_bucket_name=dict(type="bool", default=True),
expected_bucket_owner=dict(type="str"),
)

required_if = [
Expand Down
Loading