Skip to content

Commit

Permalink
user: Use IPAAnsibleModule method to validate arguments.
Browse files Browse the repository at this point in the history
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
  • Loading branch information
rjeffman committed Oct 1, 2021
1 parent f3dd95a commit d9f8d0b
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions plugins/modules/ipauser.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def check_parameters( # pylint: disable=unused-argument
userauthtype, userclass, radius, radiususer, departmentnumber,
employeenumber, employeetype, preferredlanguage, certificate,
certmapdata, noprivate, nomembers, preserve, update_password):
invalid = []
if state == "present":
if action == "member":
invalid = ["first", "last", "fullname", "displayname", "initials",
Expand All @@ -608,11 +609,6 @@ def check_parameters( # pylint: disable=unused-argument
"departmentnumber", "employeenumber", "employeetype",
"preferredlanguage", "noprivate", "nomembers",
"preserve", "update_password"]
for x in invalid:
if vars()[x] is not None:
module.fail_json(
msg="Argument '%s' can not be used with action "
"'%s'" % (x, action))

else:
invalid = ["first", "last", "fullname", "displayname", "initials",
Expand All @@ -628,16 +624,13 @@ def check_parameters( # pylint: disable=unused-argument
invalid.extend(["principal", "manager",
"certificate", "certmapdata",
])
for x in invalid:
if vars()[x] is not None:
module.fail_json(
msg="Argument '%s' can not be used with state '%s'" %
(x, state))

if state != "absent" and preserve is not None:
module.fail_json(
msg="Preserve is only possible for state=absent")

module.params_fail_if_used(invalid, state, action)

if certmapdata is not None:
for x in certmapdata:
certificate = x.get("certificate")
Expand Down

0 comments on commit d9f8d0b

Please sign in to comment.