mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-29 19:04:42 +00:00
sudorule: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate arguments provided by user.
This commit is contained in:
@@ -311,6 +311,7 @@ def main():
|
|||||||
state = ansible_module.params_get("state")
|
state = ansible_module.params_get("state")
|
||||||
|
|
||||||
# Check parameters
|
# Check parameters
|
||||||
|
invalid = []
|
||||||
|
|
||||||
if state == "present":
|
if state == "present":
|
||||||
if len(names) != 1:
|
if len(names) != 1:
|
||||||
@@ -321,11 +322,6 @@ def main():
|
|||||||
"cmdcategory", "runasusercategory",
|
"cmdcategory", "runasusercategory",
|
||||||
"runasgroupcategory", "order", "nomembers"]
|
"runasgroupcategory", "order", "nomembers"]
|
||||||
|
|
||||||
for arg in invalid:
|
|
||||||
if arg in vars() and vars()[arg] is not None:
|
|
||||||
ansible_module.fail_json(
|
|
||||||
msg="Argument '%s' can not be used with action "
|
|
||||||
"'%s'" % (arg, action))
|
|
||||||
else:
|
else:
|
||||||
if hostcategory == 'all' and any([host, hostgroup]):
|
if hostcategory == 'all' and any([host, hostgroup]):
|
||||||
ansible_module.fail_json(
|
ansible_module.fail_json(
|
||||||
@@ -349,11 +345,6 @@ def main():
|
|||||||
"runasuser", "runasgroup", "allow_sudocmd",
|
"runasuser", "runasgroup", "allow_sudocmd",
|
||||||
"allow_sudocmdgroup", "deny_sudocmd",
|
"allow_sudocmdgroup", "deny_sudocmd",
|
||||||
"deny_sudocmdgroup", "sudooption"])
|
"deny_sudocmdgroup", "sudooption"])
|
||||||
for arg in invalid:
|
|
||||||
if vars()[arg] is not None:
|
|
||||||
ansible_module.fail_json(
|
|
||||||
msg="Argument '%s' can not be used with state '%s'" %
|
|
||||||
(arg, state))
|
|
||||||
|
|
||||||
elif state in ["enabled", "disabled"]:
|
elif state in ["enabled", "disabled"]:
|
||||||
if len(names) < 1:
|
if len(names) < 1:
|
||||||
@@ -368,14 +359,11 @@ def main():
|
|||||||
"user", "group", "allow_sudocmd", "allow_sudocmdgroup",
|
"user", "group", "allow_sudocmd", "allow_sudocmdgroup",
|
||||||
"deny_sudocmd", "deny_sudocmdgroup", "runasuser",
|
"deny_sudocmd", "deny_sudocmdgroup", "runasuser",
|
||||||
"runasgroup", "order", "sudooption"]
|
"runasgroup", "order", "sudooption"]
|
||||||
for arg in invalid:
|
|
||||||
if vars()[arg] is not None:
|
|
||||||
ansible_module.fail_json(
|
|
||||||
msg="Argument '%s' can not be used with state '%s'" %
|
|
||||||
(arg, state))
|
|
||||||
else:
|
else:
|
||||||
ansible_module.fail_json(msg="Invalid state '%s'" % state)
|
ansible_module.fail_json(msg="Invalid state '%s'" % state)
|
||||||
|
|
||||||
|
ansible_module.params_fail_used_invalid(invalid, state, action)
|
||||||
|
|
||||||
# Init
|
# Init
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
Reference in New Issue
Block a user