1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #8761/982b8d89 backport][stable-8] keycloak_user_federation: sort desired and after mappers by name (#8836)

keycloak_user_federation: sort desired and after mappers by name (#8761)

* sort desired mappers by name

* sort mappers fetched after update by name

* only sort mapper list if there are desired mappers specified

* add fallback `''` in case `name` is not a key or `None` when sorting mappers

* add changelog fragment

(cherry picked from commit 982b8d89b7)

Co-authored-by: fgruenbauer <gruenbauer@b1-systems.de>
This commit is contained in:
patchback[bot] 2024-09-08 14:45:24 +02:00 committed by GitHub
parent 765fc79d28
commit 586fdefa75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- keycloak_user_federation - sort desired and after mapper list by name (analog to before mapper list) to minimize diff and make change detection more accurate (https://github.com/ansible-collections/community.general/pull/8761).

View file

@ -868,7 +868,7 @@ def main():
# if user federation exists, get associated mappers # if user federation exists, get associated mappers
if cid is not None and before_comp: if cid is not None and before_comp:
before_comp['mappers'] = sorted(kc.get_components(urlencode(dict(parent=cid)), realm), key=lambda x: x.get('name')) before_comp['mappers'] = sorted(kc.get_components(urlencode(dict(parent=cid)), realm), key=lambda x: x.get('name') or '')
# Build a proposed changeset from parameters given to this module # Build a proposed changeset from parameters given to this module
changeset = {} changeset = {}
@ -909,6 +909,7 @@ def main():
if changeset.get('mappers') is None: if changeset.get('mappers') is None:
changeset['mappers'] = list() changeset['mappers'] = list()
changeset['mappers'].append(new_mapper) changeset['mappers'].append(new_mapper)
changeset['mappers'] = sorted(changeset['mappers'], key=lambda x: x.get('name') or '')
# Prepare the desired values using the existing values (non-existence results in a dict that is save to use as a basis) # Prepare the desired values using the existing values (non-existence results in a dict that is save to use as a basis)
desired_comp = before_comp.copy() desired_comp = before_comp.copy()
@ -1018,7 +1019,7 @@ def main():
kc.create_component(mapper, realm) kc.create_component(mapper, realm)
after_comp = kc.get_component(cid, realm) after_comp = kc.get_component(cid, realm)
after_comp['mappers'] = kc.get_components(urlencode(dict(parent=cid)), realm) after_comp['mappers'] = sorted(kc.get_components(urlencode(dict(parent=cid)), realm), key=lambda x: x.get('name') or '')
after_comp_sanitized = sanitize(after_comp) after_comp_sanitized = sanitize(after_comp)
before_comp_sanitized = sanitize(before_comp) before_comp_sanitized = sanitize(before_comp)
result['end_state'] = after_comp_sanitized result['end_state'] = after_comp_sanitized