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-9] keycloak_user_federation: sort desired and after mappers by name (#8837)

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:31 +02:00 committed by GitHub
parent adda8d3113
commit aca2afc6f8
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

@ -880,7 +880,7 @@ def main():
# if user federation exists, get associated mappers
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
changeset = {}
@ -921,6 +921,7 @@ def main():
if changeset.get('mappers') is None:
changeset['mappers'] = list()
changeset['mappers'].append(new_mapper)
changeset['mappers'] = sorted(changeset['mappers'], key=lambda x: x.get('name') or '')
# to keep unspecified existing mappers we add them to the desired mappers list, unless they're already present
if not module.params['remove_unspecified_mappers'] and 'mappers' in before_comp:
@ -1036,7 +1037,7 @@ def main():
kc.create_component(mapper, 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)
before_comp_sanitized = sanitize(before_comp)
result['end_state'] = after_comp_sanitized