From f32780c46cc90b12ba67ad0011d4e5270af4260f Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 28 Dec 2024 11:43:57 +0100 Subject: [PATCH] Apply suggestions from code review lint --- changelogs/fragments/2205-support-minmax-s3lifecycle.yml | 2 +- plugins/modules/s3_lifecycle.py | 9 ++++++--- .../modules/test_s3_lifecycle_filters_are_equal.py | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/changelogs/fragments/2205-support-minmax-s3lifecycle.yml b/changelogs/fragments/2205-support-minmax-s3lifecycle.yml index 2f192ea4ec6..9eeb11d5f39 100644 --- a/changelogs/fragments/2205-support-minmax-s3lifecycle.yml +++ b/changelogs/fragments/2205-support-minmax-s3lifecycle.yml @@ -1,2 +1,2 @@ minor_changes: - - s3_lifecycle - Support for min and max object size when applying the filter rules. \ No newline at end of file + - s3_lifecycle - Support for min and max object size when applying the filter rules (https://github.com/ansible-collections/community.aws/pull/2205). \ No newline at end of file diff --git a/plugins/modules/s3_lifecycle.py b/plugins/modules/s3_lifecycle.py index c82290df250..993ee948563 100644 --- a/plugins/modules/s3_lifecycle.py +++ b/plugins/modules/s3_lifecycle.py @@ -64,10 +64,12 @@ - The maximum object size to which the rule applies. required: false type: int + version_added: 9.1.0 minimum_object_size: description: - The minimum object size to which the rule applies. required: false + version_added: 9.1.0 type: int noncurrent_version_expiration_days: description: @@ -281,6 +283,7 @@ def fetch_rules(client, module, name): module.fail_json_aws(e) return current_lifecycle_rules + # Helper function to deeply compare filters def filters_are_equal(filter1, filter2): if filter1 == filter2: @@ -296,7 +299,8 @@ def filters_are_equal(filter1, filter2): and filter1.get("And", {}).get("ObjectSizeGreaterThan") == filter2.get("And", {}).get("ObjectSizeGreaterThan") and filter1.get("And", {}).get("ObjectSizeLessThan") == filter2.get("And", {}).get("ObjectSizeLessThan") ) - + + def build_rule(client, module): name = module.params.get("name") abort_incomplete_multipart_upload_days = module.params.get("abort_incomplete_multipart_upload_days") @@ -397,7 +401,6 @@ def compare_and_update_configuration(client, module, current_lifecycle_rules, ru lifecycle_configuration = dict(Rules=[]) changed = False appended = False - # If current_lifecycle_obj is not None then we have rules to compare, otherwise just add the rule if current_lifecycle_rules: # If rule ID exists, use that for comparison otherwise compare based on prefix @@ -714,4 +717,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py b/tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py index 8a3f0b4bbb0..54cdee2d761 100644 --- a/tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py +++ b/tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py @@ -78,8 +78,8 @@ def test_filters_are_equal(): } filter2 = { "And": { - "Prefix": "nested/", # Different key/value - "ObjectSizeLessThan": 150, + "Prefix": "nested/", # Different key/value + "ObjectSizeLessThan": 150, }, } assert filters_are_equal(filter1, filter2) is False @@ -105,4 +105,4 @@ def test_filters_are_equal(): filter2 = { "Prefix": "" } - assert filters_are_equal(filter1, filter2) is True \ No newline at end of file + assert filters_are_equal(filter1, filter2) is True