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 fragmentpull/9012/head
parent
1bdf8fc025
commit
c814fd0530
|
@ -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']['person-name-prohibited-characters'] = (
|
||||||
attribute['validations'].pop('personNameProhibitedCharacters')
|
attribute['validations'].pop('personNameProhibitedCharacters')
|
||||||
)
|
)
|
||||||
# special JSON parsing for kc_user_profile_config
|
changeset[camel(component_param)][config_param].append(kc_user_profile_config[0])
|
||||||
value = json.dumps(kc_user_profile_config[0])
|
|
||||||
changeset[camel(component_param)][config_param].append(value)
|
|
||||||
# usual camelCase parameters
|
# usual camelCase parameters
|
||||||
else:
|
else:
|
||||||
changeset[camel(component_param)][camel(config_param)] = []
|
changeset[camel(component_param)][camel(config_param)] = []
|
||||||
|
@ -662,6 +660,10 @@ def main():
|
||||||
changeset['id'] = userprofile_id
|
changeset['id'] = userprofile_id
|
||||||
changeset_copy['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
|
# Compare top-level parameters
|
||||||
for param, value in changeset.items():
|
for param, value in changeset.items():
|
||||||
before_realm_userprofile[param] = userprofile[param]
|
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
|
# Check all the possible states of the resource and do what is needed to
|
||||||
# converge current state with desired state (create, update or delete
|
# converge current state with desired state (create, update or delete
|
||||||
# the userprofile).
|
# 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 userprofile_id and state == 'present':
|
||||||
if result['changed']:
|
if result['changed']:
|
||||||
if module._diff:
|
if module._diff:
|
||||||
|
|
|
@ -17,6 +17,8 @@ from ansible_collections.community.general.plugins.modules import keycloak_userp
|
||||||
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
|
from json import dumps
|
||||||
|
|
||||||
from ansible.module_utils.six import StringIO
|
from ansible.module_utils.six import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
@ -509,7 +511,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
||||||
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
||||||
"config": {
|
"config": {
|
||||||
"kc.user.profile.config": [
|
"kc.user.profile.config": [
|
||||||
{
|
dumps({
|
||||||
"attributes": [
|
"attributes": [
|
||||||
{
|
{
|
||||||
"name": "username",
|
"name": "username",
|
||||||
|
@ -625,7 +627,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
||||||
"displayDescription": "Attributes, which refer to user metadata",
|
"displayDescription": "Attributes, which refer to user metadata",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -714,7 +716,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
||||||
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
"providerType": "org.keycloak.userprofile.UserProfileProvider",
|
||||||
"config": {
|
"config": {
|
||||||
"kc.user.profile.config": [
|
"kc.user.profile.config": [
|
||||||
{
|
dumps({
|
||||||
"attributes": [
|
"attributes": [
|
||||||
{
|
{
|
||||||
"name": "username",
|
"name": "username",
|
||||||
|
@ -830,7 +832,7 @@ class TestKeycloakUserprofile(ModuleTestCase):
|
||||||
"displayDescription": "Attributes, which refer to user metadata",
|
"displayDescription": "Attributes, which refer to user metadata",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue