-
Notifications
You must be signed in to change notification settings - Fork 343
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
s3_object: Add parameter acl_disabled
to handle uploading files to buckets with ACL disabled.
#921
Merged
softwarefactory-project-zuul
merged 12 commits into
ansible-collections:main
from
mandar242:s3_object_acl_disabled_bucket_file_upload
Jul 19, 2022
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4fbd135
Add parameter to handle uploading files to buckets with ACL disabled
mandar242 3af8dac
Change acl_disabled user input param to an internal check for acl ena…
mandar242 c3662ad
sanity fix
mandar242 2ce242e
fix condition when bucket does not exist or does not have ownershipco…
mandar242 5db8849
Add logic to handle case when bucket ownership control not found
mandar242 65147fe
Add logic to handle case when bucket ownership control not found
mandar242 b46adf7
Add integration tests
mandar242 6b97c22
Remove debugging statements in integration test
mandar242 d8050a2
Add changelogs fragment
mandar242 62e10e0
Move acl_disabled from module.param to a variable
mandar242 da588d2
Add 'setup_remote_tmp_dir' role to handle temp directory creation
mandar242 a495505
Modified based on feedback
mandar242 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/921-s3_object-handle-file-upload-to-acl-disabled-bucket.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- s3_object - updated module to add support for handling file upload to a bucket with ACL disabled (https://github.com/ansible-collections/amazon.aws/pull/921). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
- setup_remote_tmp_dir |
111 changes: 111 additions & 0 deletions
111
tests/integration/targets/s3_object/tasks/copy_object_acl_disabled_bucket.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
- name: test copying objects to bucket with ACL disabled | ||
block: | ||
- name: Create a bucket with ACL disabled for the test | ||
s3_bucket: | ||
name: "{{ bucket_name }}-acl-disabled" | ||
object_ownership: BucketOwnerEnforced | ||
state: present | ||
register: create_result | ||
|
||
- name: Ensure bucket creation | ||
assert: | ||
that: | ||
- create_result is changed | ||
- create_result is not failed | ||
- create_result.object_ownership == "BucketOwnerEnforced" | ||
|
||
- name: Create content | ||
set_fact: | ||
content: "{{ lookup('password', '/dev/null chars=ascii_letters,digits,hexdigits,punctuation') }}" | ||
|
||
- name: Create local acl_disabled_upload_test.txt | ||
copy: | ||
content: "{{ content }}" | ||
dest: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
|
||
- name: Upload a file to the bucket (check_mode) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
check_mode: true | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg == "PUT operation skipped - running in check mode" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg == "PUT operation complete" | ||
- '"s3:PutObject" in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket (check_mode - idempotency) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
check_mode: true | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is not changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg != "PUT operation complete" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
- name: Upload a file to the bucket (idempotency) | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: put | ||
register: upload_file_result | ||
|
||
- assert: | ||
that: | ||
- upload_file_result is not changed | ||
- upload_file_result is not failed | ||
- upload_file_result.msg != "PUT operation complete" | ||
- '"s3:PutObject" not in upload_file_result.resource_actions' | ||
|
||
always: | ||
|
||
- name: Delete the file in the bucket | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}-acl-disabled" | ||
src: "{{ remote_tmp_dir }}/acl_disabled_upload_test.txt" | ||
object: "acl_disabled_upload_test.txt" | ||
mode: delobj | ||
retries: 3 | ||
delay: 3 | ||
ignore_errors: true | ||
|
||
- name: Delete bucket created in this test | ||
s3_bucket: | ||
name: "{{ bucket_name }}-acl-disabled" | ||
object_ownership: BucketOwnerEnforced | ||
state: absent | ||
register: delete_result | ||
|
||
- name: Ensure bucket deletion | ||
assert: | ||
that: | ||
- delete_result is changed | ||
- delete_result is not failed |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you should also remove the temp dir you created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or better, use the helper role which adds a handler - https://github.com/ansible-collections/community.aws/blob/main/tests/integration/targets/acm_certificate/meta/main.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.