mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-21 03:09:04 +00:00
[PR #11859/dad84dd3 backport][stable-12] udm_user - fix alias-to-canonical param name mismatch (#11863)
udm_user - fix alias-to-canonical param name mismatch (#11859)
* udm_user - fix alias-to-canonical param name mismatch
The loop that maps UDM object properties to module params iterated
over UDM keys (camelCase, e.g. displayName, primaryGroup) and looked
them up directly in module.params, which is keyed by canonical names
(snake_case, e.g. display_name, primary_group). This caused all
aliased params to be silently ignored.
Build an alias-to-canonical mapping from argument_spec and use it
to resolve UDM keys to the correct module.params entries.
Also fix the direct module.params["displayName"] access which raised
KeyError when the user did not explicitly use the alias form.
Fixes #2950
Fixes #3691
* Add changelog fragment for PR 11859
---------
(cherry picked from commit dad84dd36d)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
119623952d
commit
7b82e694a2
2 changed files with 19 additions and 5 deletions
|
|
@ -444,19 +444,27 @@ def main():
|
|||
else:
|
||||
obj = umc_module_for_edit("users/user", user_dn)
|
||||
|
||||
if module.params["displayName"] is None:
|
||||
module.params["displayName"] = f"{module.params['firstname']} {module.params['lastname']}"
|
||||
if module.params["display_name"] is None:
|
||||
module.params["display_name"] = f"{module.params['firstname']} {module.params['lastname']}"
|
||||
if module.params["unixhome"] is None:
|
||||
module.params["unixhome"] = f"/home/{module.params['username']}"
|
||||
# Build a mapping from alias names to canonical param names,
|
||||
# so that UDM object keys (camelCase) can be resolved to the
|
||||
# corresponding module.params keys (snake_case).
|
||||
alias_to_param = {}
|
||||
for param_name, param_spec in module.argument_spec.items():
|
||||
for alias in param_spec.get("aliases", []):
|
||||
alias_to_param[alias] = param_name
|
||||
for k in obj.keys():
|
||||
param_name = alias_to_param.get(k, k)
|
||||
if (
|
||||
k != "password"
|
||||
and k != "groups"
|
||||
and k != "overridePWHistory"
|
||||
and k in module.params
|
||||
and module.params[k] is not None
|
||||
and param_name in module.params
|
||||
and module.params[param_name] is not None
|
||||
):
|
||||
obj[k] = module.params[k]
|
||||
obj[k] = module.params[param_name]
|
||||
# handle some special values
|
||||
obj["e-mail"] = module.params["email"]
|
||||
if "userexpiry" in obj and obj.get("userexpiry") is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue