Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
tremble authored Dec 28, 2024
1 parent 7c50572 commit f32780c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion changelogs/fragments/2205-support-minmax-s3lifecycle.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minor_changes:
- s3_lifecycle - Support for min and max object size when applying the filter rules.
- s3_lifecycle - Support for min and max object size when applying the filter rules (https://github.com/ansible-collections/community.aws/pull/2205).
9 changes: 6 additions & 3 deletions plugins/modules/s3_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -714,4 +717,4 @@ def main():


if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -105,4 +105,4 @@ def test_filters_are_equal():
filter2 = {
"Prefix": ""
}
assert filters_are_equal(filter1, filter2) is True
assert filters_are_equal(filter1, filter2) is True

0 comments on commit f32780c

Please sign in to comment.