mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +00:00
[PR #11515/7cd75945 backport][stable-12] #11502 Fix mapping of config of keycloak_user_federation (#11529)
#11502 Fix mapping of config of keycloak_user_federation (#11515)
* #11502 Fix mapping of config
Fix mapping of config
Fix diff for mappers
* Fix formatting with nox
* Update changelogs/fragments/11502-keycloak-config-mapper.yaml
* Remove duplicate comment
https://github.com/ansible-collections/community.general/pull/11515#discussion_r2821444756
---------
(cherry picked from commit 7cd75945b2)
Co-authored-by: mixman68 <greg.djg13@gmail.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
696b6e737a
commit
d3dd685ad4
2 changed files with 28 additions and 7 deletions
2
changelogs/fragments/11502-keycloak-config-mapper.yaml
Normal file
2
changelogs/fragments/11502-keycloak-config-mapper.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "keycloak_user_federation - mapper config item can be an array (https://github.com/ansible-collections/community.general/issues/11502, https://github.com/ansible-collections/community.general/pull/11515)."
|
||||
|
|
@ -744,15 +744,30 @@ def normalize_kc_comp(comp):
|
|||
|
||||
|
||||
def sanitize(comp):
|
||||
def sanitize_value(v):
|
||||
"""Convert list values: single-element lists to strings, multi-element lists sorted alphabetically, others as-is."""
|
||||
if isinstance(v, list):
|
||||
if len(v) == 0:
|
||||
return None
|
||||
elif len(v) == 1:
|
||||
return v[0]
|
||||
else:
|
||||
return sorted(v)
|
||||
else:
|
||||
return v
|
||||
|
||||
compcopy = deepcopy(comp)
|
||||
if "config" in compcopy:
|
||||
compcopy["config"] = {k: v[0] for k, v in compcopy["config"].items()}
|
||||
compcopy["config"] = {k: sanitize_value(v) for k, v in compcopy["config"].items()}
|
||||
# Remove None values (empty lists converted)
|
||||
compcopy["config"] = {k: v for k, v in compcopy["config"].items() if v is not None}
|
||||
if "bindCredential" in compcopy["config"]:
|
||||
compcopy["config"]["bindCredential"] = "**********"
|
||||
if "mappers" in compcopy:
|
||||
for mapper in compcopy["mappers"]:
|
||||
if "config" in mapper:
|
||||
mapper["config"] = {k: v[0] for k, v in mapper["config"].items()}
|
||||
mapper["config"] = {k: sanitize_value(v) for k, v in mapper["config"].items()}
|
||||
mapper["config"] = {k: v for k, v in mapper["config"].items() if v is not None}
|
||||
return compcopy
|
||||
|
||||
|
||||
|
|
@ -886,11 +901,15 @@ def main():
|
|||
if mappers is not None:
|
||||
for mapper in mappers:
|
||||
if mapper.get("config") is not None:
|
||||
mapper["config"] = {
|
||||
k: [str(v).lower() if not isinstance(v, str) else v]
|
||||
for k, v in mapper["config"].items()
|
||||
if mapper["config"][k] is not None
|
||||
}
|
||||
new_config = {}
|
||||
for k, v in mapper["config"].items():
|
||||
if v is None:
|
||||
continue
|
||||
if isinstance(v, list):
|
||||
new_config[k] = [str(item).lower() if not isinstance(item, str) else item for item in v]
|
||||
else:
|
||||
new_config[k] = [str(v).lower() if not isinstance(v, str) else v]
|
||||
mapper["config"] = new_config
|
||||
|
||||
# Filter and map the parameters names that apply
|
||||
comp_params = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue