[PR #9093/8fc11fe8 backport][stable-9] keycloak_clientscope_type fix checkmode (#9095)

keycloak_clientscope_type fix checkmode (#9093)

* fix check_mode on set keycloak client scope type (#9092)

* add changelog fragment (#9092)

* update changelog fragment (#9092)

* compact code: make one line conditions with list comprehension and any()

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

* fix syntax error: remove extra ')'

* fix changelog fragment type

Co-authored-by: Felix Fontein <felix@fontein.de>

* add issue's link in changelog fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 8fc11fe88f)

Co-authored-by: witrdotnet <witr.net@gmail.com>
pull/9100/head
patchback[bot] 2024-11-03 11:30:16 +01:00 committed by GitHub
parent eb14bd572d
commit 5fd97399b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- keycloak_clientscope_type - fix detect changes in check mode (https://github.com/ansible-collections/community.general/issues/9092, https://github.com/ansible-collections/community.general/pull/9093).

View File

@ -246,15 +246,19 @@ def main():
if module._diff: if module._diff:
result['diff'] = dict(before=result['existing'], after=result['proposed']) result['diff'] = dict(before=result['existing'], after=result['proposed'])
if module.check_mode:
module.exit_json(**result)
default_clientscopes_add = clientscopes_to_add(default_clientscopes_existing, default_clientscopes_real) default_clientscopes_add = clientscopes_to_add(default_clientscopes_existing, default_clientscopes_real)
optional_clientscopes_add = clientscopes_to_add(optional_clientscopes_existing, optional_clientscopes_real) optional_clientscopes_add = clientscopes_to_add(optional_clientscopes_existing, optional_clientscopes_real)
default_clientscopes_delete = clientscopes_to_delete(default_clientscopes_existing, default_clientscopes_real) default_clientscopes_delete = clientscopes_to_delete(default_clientscopes_existing, default_clientscopes_real)
optional_clientscopes_delete = clientscopes_to_delete(optional_clientscopes_existing, optional_clientscopes_real) optional_clientscopes_delete = clientscopes_to_delete(optional_clientscopes_existing, optional_clientscopes_real)
result["changed"] = any(len(x) > 0 for x in [
default_clientscopes_add, optional_clientscopes_add, default_clientscopes_delete, optional_clientscopes_delete
])
if module.check_mode:
module.exit_json(**result)
# first delete so clientscopes can change type # first delete so clientscopes can change type
for clientscope in default_clientscopes_delete: for clientscope in default_clientscopes_delete:
kc.delete_default_clientscope(clientscope['id'], realm, client_id) kc.delete_default_clientscope(clientscope['id'], realm, client_id)
@ -266,13 +270,6 @@ def main():
for clientscope in optional_clientscopes_add: for clientscope in optional_clientscopes_add:
kc.add_optional_clientscope(clientscope['id'], realm, client_id) kc.add_optional_clientscope(clientscope['id'], realm, client_id)
result["changed"] = (
len(default_clientscopes_add) > 0
or len(optional_clientscopes_add) > 0
or len(default_clientscopes_delete) > 0
or len(optional_clientscopes_delete) > 0
)
result['end_state'].update({ result['end_state'].update({
'default_clientscopes': extract_field(kc.get_default_clientscopes(realm, client_id)), 'default_clientscopes': extract_field(kc.get_default_clientscopes(realm, client_id)),
'optional_clientscopes': extract_field(kc.get_optional_clientscopes(realm, client_id)) 'optional_clientscopes': extract_field(kc.get_optional_clientscopes(realm, client_id))