mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-21 20:59:10 +00:00
* #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 Co-authored-by: Felix Fontein <felix@fontein.de> * Remove duplicate comment https://github.com/ansible-collections/community.general/pull/11515#discussion_r2821444756 --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
1ae058db63
commit
7cd75945b2
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(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)
|
compcopy = deepcopy(comp)
|
||||||
if "config" in compcopy:
|
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"]:
|
if "bindCredential" in compcopy["config"]:
|
||||||
compcopy["config"]["bindCredential"] = "**********"
|
compcopy["config"]["bindCredential"] = "**********"
|
||||||
if "mappers" in compcopy:
|
if "mappers" in compcopy:
|
||||||
for mapper in compcopy["mappers"]:
|
for mapper in compcopy["mappers"]:
|
||||||
if "config" in mapper:
|
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
|
return compcopy
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -886,11 +901,15 @@ def main():
|
||||||
if mappers is not None:
|
if mappers is not None:
|
||||||
for mapper in mappers:
|
for mapper in mappers:
|
||||||
if mapper.get("config") is not None:
|
if mapper.get("config") is not None:
|
||||||
mapper["config"] = {
|
new_config = {}
|
||||||
k: [str(v).lower() if not isinstance(v, str) else v]
|
for k, v in mapper["config"].items():
|
||||||
for k, v in mapper["config"].items()
|
if v is None:
|
||||||
if mapper["config"][k] is not 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
|
# Filter and map the parameters names that apply
|
||||||
comp_params = [
|
comp_params = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue