Skip to content

Commit

Permalink
s3-lifecycle: fix remove rule with empty prefix (ansible-collections#…
Browse files Browse the repository at this point in the history
…1398)

s3-lifecycle: fix remove rule with empty prefix

SUMMARY
In case of removing a lifecycle policy without a prefix, there will be no prefix key in the existing_rule filter
Signed-off-by: Seena Fallah [email protected]
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
s3_lifecycle

Reviewed-by: Mark Chappell <None>
  • Loading branch information
clwluvw authored Aug 8, 2022
1 parent 8308539 commit 485de9b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions s3_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ def compare_and_update_configuration(client, module, current_lifecycle_rules, ru
if current_lifecycle_rules:
# If rule ID exists, use that for comparison otherwise compare based on prefix
for existing_rule in current_lifecycle_rules:
if rule.get('ID') == existing_rule.get('ID') and rule['Filter']['Prefix'] != existing_rule.get('Filter', {}).get('Prefix', ''):
if rule.get('ID') == existing_rule.get('ID') and rule['Filter'].get('Prefix', '') != existing_rule.get('Filter', {}).get('Prefix', ''):
existing_rule.pop('ID')
elif rule_id is None and rule['Filter']['Prefix'] == existing_rule.get('Filter', {}).get('Prefix', ''):
elif rule_id is None and rule['Filter'].get('Prefix', '') == existing_rule.get('Filter', {}).get('Prefix', ''):
existing_rule.pop('ID')
if rule.get('ID') == existing_rule.get('ID'):
changed_, appended_ = update_or_append_rule(rule, existing_rule, purge_transitions, lifecycle_configuration)
Expand Down Expand Up @@ -407,7 +407,7 @@ def compare_and_remove_rule(current_lifecycle_rules, rule_id=None, prefix=None):
lifecycle_configuration['Rules'].append(existing_rule)
else:
for existing_rule in current_lifecycle_rules:
if prefix == existing_rule['Filter']['Prefix']:
if prefix == existing_rule['Filter'].get('Prefix', ''):
# We're not keeping the rule (i.e. deleting) so mark as changed
changed = True
else:
Expand Down

0 comments on commit 485de9b

Please sign in to comment.