Skip to content

Commit

Permalink
ecs_ecr - Use compare_policies instead of naive dict sort (ansible-co…
Browse files Browse the repository at this point in the history
…llections#1551)

ecs_ecr - Use compare_policies instead of naive dict sort

Depends-On: ansible-collections#1550
SUMMARY
When comparing policies on the repos ecs_ecr currently uses a very naive sort function.  Since we have something more comprehensive, use it.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/ecs_ecr.py
ADDITIONAL INFORMATION
ecs_ecr is currently the only module using sort_json_policy_dict and it has poor test coverage.

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
tremble authored Oct 7, 2022
1 parent 187649d commit 021c001
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ecs_ecr - use ``compare_policies`` when comparing lifecycle policies instead of naive ``sort_json_policy_dict`` comparisons (https://github.com/ansible-collections/community.aws/pull/1551).
9 changes: 1 addition & 8 deletions plugins/modules/ecs_ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto_exception
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_policies
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import sort_json_policy_dict


def build_kwargs(registry_id):
Expand Down Expand Up @@ -457,17 +456,11 @@ def run(ecr, params):

elif lifecycle_policy_text is not None:
try:
lifecycle_policy = sort_json_policy_dict(lifecycle_policy)
result['lifecycle_policy'] = lifecycle_policy

original_lifecycle_policy = ecr.get_lifecycle_policy(
registry_id, name)

if original_lifecycle_policy:
original_lifecycle_policy = sort_json_policy_dict(
original_lifecycle_policy)

if original_lifecycle_policy != lifecycle_policy:
if compare_policies(original_lifecycle_policy, lifecycle_policy):
ecr.put_lifecycle_policy(registry_id, name,
lifecycle_policy_text)
result['changed'] = True
Expand Down

0 comments on commit 021c001

Please sign in to comment.