[PR #8940/c814fd05 backport][stable-9] keycloak_userprofile: improve diff by deserializing fetched `kc.user.profile.config` and serializing it before sending (#9002)
keycloak_userprofile: improve diff by deserializing fetched `kc.user.profile.config` and serializing it before sending (#8940)
* deserialize fetched `kc.user.profile.config` and serialize it before sending
* change `kc.user.profile.config` to JSON formatted string in mock `get_component` responses
* add changelog fragment
(cherry picked from commit c814fd0530
)
Co-authored-by: fgruenbauer <gruenbauer@b1-systems.de>
pull/9014/head
parent
acdf19c9e6
commit
a1d4051a12
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- keycloak_userprofile - improve diff by deserializing the fetched ``kc.user.profile.config`` and serialize it only when sending back (https://github.com/ansible-collections/community.general/pull/8940).
|
|
@ -612,9 +612,7 @@ def main():
|
|||
attribute['validations']['person-name-prohibited-characters'] = (
|
||||
attribute['validations'].pop('personNameProhibitedCharacters')
|
||||
)
|
||||
# special JSON parsing for kc_user_profile_config
|
||||
value = json.dumps(kc_user_profile_config[0])
|
||||
changeset[camel(component_param)][config_param].append(value)
|
||||
changeset[camel(component_param)][config_param].append(kc_user_profile_config[0])
|
||||
# usual camelCase parameters
|
||||
else:
|
||||
changeset[camel(component_param)][camel(config_param)] = []
|
||||
|
@ -662,6 +660,10 @@ def main():
|
|||
changeset['id'] = userprofile_id
|
||||
changeset_copy['id'] = userprofile_id
|
||||
|
||||
# keycloak returns kc.user.profile.config as a single JSON formatted string, so we have to deserialize it
|
||||
if 'config' in userprofile and 'kc.user.profile.config' in userprofile['config']:
|
||||
userprofile['config']['kc.user.profile.config'][0] = json.loads(userprofile['config']['kc.user.profile.config'][0])
|
||||
|
||||
# Compare top-level parameters
|
||||
for param, value in changeset.items():
|
||||
before_realm_userprofile[param] = userprofile[param]
|
||||
|
@ -680,6 +682,10 @@ def main():
|
|||
# Check all the possible states of the resource and do what is needed to
|
||||
# converge current state with desired state (create, update or delete
|
||||
# the userprofile).
|
||||
|
||||
# keycloak expects kc.user.profile.config as a single JSON formatted string, so we have to serialize it
|
||||
if 'config' in changeset and 'kc.user.profile.config' in changeset['config']:
|
||||
changeset['config']['kc.user.profile.config'][0] = json.dumps(changeset['config']['kc.user.profile.config'][0])
|
||||
if userprofile_id and state == 'present':
|
||||
if result['changed']:
|
||||
if module._diff:
|
||||
|
|
|
@ -17,6 +17,8 @@ from ansible_collections.community.general.plugins.modules import keycloak_userp
|
|||
|
||||
from itertools import count
|
||||
|
||||
from json import dumps
|
||||
|
||||
from ansible.module_utils.six import StringIO
|
||||
|
||||
|
||||
|
@ -509,7 +511,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
|||
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
||||
"config": {
|
||||
"kc.user.profile.config": [
|
||||
{
|
||||
dumps({
|
||||
"attributes": [
|
||||
{
|
||||
"name": "username",
|
||||
|
@ -625,7 +627,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
|||
"displayDescription": "Attributes, which refer to user metadata",
|
||||
}
|
||||
],
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -714,7 +716,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
|||
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
||||
"config": {
|
||||
"kc.user.profile.config": [
|
||||
{
|
||||
dumps({
|
||||
"attributes": [
|
||||
{
|
||||
"name": "username",
|
||||
|
@ -830,7 +832,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
|||
"displayDescription": "Attributes, which refer to user metadata",
|
||||
}
|
||||
],
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue