From 2583e3993df105f2c027b1000e50fc7c603fb027 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 21 Apr 2024 09:10:44 +0200 Subject: [PATCH] [PR #8224/9d66a1dc backport][stable-7] keycloak_realm: add normalizations for enabledEventTypes, and supportedLocales (#8255) keycloak_realm: add normalizations for enabledEventTypes, and supportedLocales (#8224) keycloak_realm: add nomalizations for enabledEventTypes, and supportedLocales Signed-off-by: Eike Waldt (cherry picked from commit 9d66a1dc1e54c242c899fe1dc6c1ceab7871a894) Co-authored-by: Eike Waldt --- ...224-keycloak_realm-add-normalizations.yaml | 2 ++ plugins/modules/keycloak_realm.py | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/8224-keycloak_realm-add-normalizations.yaml diff --git a/changelogs/fragments/8224-keycloak_realm-add-normalizations.yaml b/changelogs/fragments/8224-keycloak_realm-add-normalizations.yaml new file mode 100644 index 0000000000..0574141f61 --- /dev/null +++ b/changelogs/fragments/8224-keycloak_realm-add-normalizations.yaml @@ -0,0 +1,2 @@ +bugfixes: + - keycloak_realm - add normalizations for ``enabledEventTypes`` and ``supportedLocales`` (https://github.com/ansible-collections/community.general/pull/8224). diff --git a/plugins/modules/keycloak_realm.py b/plugins/modules/keycloak_realm.py index 9f2e72b525..6128c9e4c7 100644 --- a/plugins/modules/keycloak_realm.py +++ b/plugins/modules/keycloak_realm.py @@ -582,6 +582,27 @@ from ansible_collections.community.general.plugins.module_utils.identity.keycloa from ansible.module_utils.basic import AnsibleModule +def normalise_cr(realmrep): + """ Re-sorts any properties where the order is important so that diff's is minimised and the change detection is more effective. + + :param realmrep: the realmrep dict to be sanitized + :return: normalised realmrep dict + """ + # Avoid the dict passed in to be modified + realmrep = realmrep.copy() + + if 'enabledEventTypes' in realmrep: + realmrep['enabledEventTypes'] = list(sorted(realmrep['enabledEventTypes'])) + + if 'otpSupportedApplications' in realmrep: + realmrep['otpSupportedApplications'] = list(sorted(realmrep['otpSupportedApplications'])) + + if 'supportedLocales' in realmrep: + realmrep['supportedLocales'] = list(sorted(realmrep['supportedLocales'])) + + return realmrep + + def sanitize_cr(realmrep): """ Removes probably sensitive details from a realm representation. @@ -595,7 +616,7 @@ def sanitize_cr(realmrep): if 'saml.signing.private.key' in result['attributes']: result['attributes'] = result['attributes'].copy() result['attributes']['saml.signing.private.key'] = '********' - return result + return normalise_cr(result) def main(): @@ -777,9 +798,11 @@ def main(): result['changed'] = True if module.check_mode: # We can only compare the current realm with the proposed updates we have + before_norm = normalise_cr(before_realm) + desired_norm = normalise_cr(desired_realm) if module._diff: - result['diff'] = dict(before=before_realm_sanitized, - after=sanitize_cr(desired_realm)) + result['diff'] = dict(before=sanitize_cr(before_norm), + after=sanitize_cr(desired_norm)) result['changed'] = (before_realm != desired_realm) module.exit_json(**result)