mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 05:09:12 +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
|
|
@ -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