From 021c0019d3bc99b4e02f6c8c7e054f3392209550 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 7 Oct 2022 14:19:15 +0200 Subject: [PATCH] ecs_ecr - Use compare_policies instead of naive dict sort (#1551) ecs_ecr - Use compare_policies instead of naive dict sort Depends-On: #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 --- changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml | 2 ++ plugins/modules/ecs_ecr.py | 9 +-------- 2 files changed, 3 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml diff --git a/changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml b/changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml new file mode 100644 index 00000000000..2f6442c86f9 --- /dev/null +++ b/changelogs/fragments/1551-ecs_ecr-sort_json_policy.yml @@ -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). diff --git a/plugins/modules/ecs_ecr.py b/plugins/modules/ecs_ecr.py index 1323bc6c35a..d472af2756c 100644 --- a/plugins/modules/ecs_ecr.py +++ b/plugins/modules/ecs_ecr.py @@ -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): @@ -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