Skip to content

Commit

Permalink
[PR #9093/8fc11fe8 backport][stable-9] keycloak_clientscope_type fix …
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* fix syntax error: remove extra ')'

* fix changelog fragment type

Co-authored-by: Felix Fontein <[email protected]>

* add issue's link in changelog fragment

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Alexei Znamensky <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 8fc11fe)

Co-authored-by: witrdotnet <[email protected]>
  • Loading branch information
patchback[bot] and witrdotnet authored Nov 3, 2024
1 parent eb14bd5 commit 5fd9739
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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).
17 changes: 7 additions & 10 deletions plugins/modules/keycloak_clientscope_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,19 @@ def main():
if module._diff:
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)
optional_clientscopes_add = clientscopes_to_add(optional_clientscopes_existing, optional_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)

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
for clientscope in default_clientscopes_delete:
kc.delete_default_clientscope(clientscope['id'], realm, client_id)
Expand All @@ -266,13 +270,6 @@ def main():
for clientscope in optional_clientscopes_add:
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({
'default_clientscopes': extract_field(kc.get_default_clientscopes(realm, client_id)),
'optional_clientscopes': extract_field(kc.get_optional_clientscopes(realm, client_id))
Expand Down

0 comments on commit 5fd9739

Please sign in to comment.