From 4c6d439a13de330ca86f42812ea788d5e4a3afbe Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 26 May 2024 21:17:34 +0200 Subject: [PATCH] [PR #8403/572caeaa backport][stable-8] keycloak_client: avoid TypeError if `result["attributes"]` is a list (#8426) keycloak_client: avoid TypeError if `result["attributes"]` is a list (#8403) * fix(keycloak_client): avoid TypeError if attributes is a list As sanitize_cr might be executed after normalise_cr, result['attributes'] can be of type list and we run into: TypeError: list indices must be integers or slices, not str * Update changelog fragment. --------- Co-authored-by: Felix Fontein (cherry picked from commit 572caeaa39ad3efd6083afafba9fd4fe4c88f9fd) Co-authored-by: Thomas Bach <63091663+thomasbach-dev@users.noreply.github.com> --- .../fragments/8403-fix-typeerror-in-keycloak-client.yaml | 2 ++ plugins/modules/keycloak_client.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/8403-fix-typeerror-in-keycloak-client.yaml diff --git a/changelogs/fragments/8403-fix-typeerror-in-keycloak-client.yaml b/changelogs/fragments/8403-fix-typeerror-in-keycloak-client.yaml new file mode 100644 index 0000000000..b8acf7b09b --- /dev/null +++ b/changelogs/fragments/8403-fix-typeerror-in-keycloak-client.yaml @@ -0,0 +1,2 @@ +bugfixes: + - keycloak_client - fix TypeError when sanitizing the ``saml.signing.private.key`` attribute in the module's diff or state output. The ``sanitize_cr`` function expected a dict where in some cases a list might occur (https://github.com/ansible-collections/community.general/pull/8403). diff --git a/plugins/modules/keycloak_client.py b/plugins/modules/keycloak_client.py index cd9c60bacf..3628e5a517 100644 --- a/plugins/modules/keycloak_client.py +++ b/plugins/modules/keycloak_client.py @@ -775,8 +775,9 @@ def sanitize_cr(clientrep): if 'secret' in result: result['secret'] = 'no_log' if 'attributes' in result: - if 'saml.signing.private.key' in result['attributes']: - result['attributes']['saml.signing.private.key'] = 'no_log' + attributes = result['attributes'] + if isinstance(attributes, dict) and 'saml.signing.private.key' in attributes: + attributes['saml.signing.private.key'] = 'no_log' return normalise_cr(result)