mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-31 11:54:47 +00:00
ipapwpolicy: Use modules.params_get_type
Use the commom parameter type handling method for parameters that accept a value or an empty string.
This commit is contained in:
@@ -153,7 +153,7 @@ RETURN = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.ansible_freeipa_module import \
|
from ansible.module_utils.ansible_freeipa_module import \
|
||||||
IPAAnsibleModule, compare_args_ipa, boolean
|
IPAAnsibleModule, compare_args_ipa
|
||||||
|
|
||||||
|
|
||||||
def find_pwpolicy(module, name):
|
def find_pwpolicy(module, name):
|
||||||
@@ -294,20 +294,34 @@ def main():
|
|||||||
names = ansible_module.params_get("name")
|
names = ansible_module.params_get("name")
|
||||||
|
|
||||||
# present
|
# present
|
||||||
maxlife = ansible_module.params_get("maxlife")
|
maxlife = ansible_module.params_get_with_type_cast(
|
||||||
minlife = ansible_module.params_get("minlife")
|
"maxlife", int, allow_empty=True)
|
||||||
history = ansible_module.params_get("history")
|
minlife = ansible_module.params_get_with_type_cast(
|
||||||
minclasses = ansible_module.params_get("minclasses")
|
"minlife", int, allow_empty=True)
|
||||||
minlength = ansible_module.params_get("minlength")
|
history = ansible_module.params_get_with_type_cast(
|
||||||
priority = ansible_module.params_get("priority")
|
"history", int, allow_empty=True)
|
||||||
maxfail = ansible_module.params_get("maxfail")
|
minclasses = ansible_module.params_get_with_type_cast(
|
||||||
failinterval = ansible_module.params_get("failinterval")
|
"minclasses", int, allow_empty=True)
|
||||||
lockouttime = ansible_module.params_get("lockouttime")
|
minlength = ansible_module.params_get_with_type_cast(
|
||||||
maxrepeat = ansible_module.params_get("maxrepeat")
|
"minlength", int, allow_empty=True)
|
||||||
maxsequence = ansible_module.params_get("maxsequence")
|
priority = ansible_module.params_get_with_type_cast(
|
||||||
dictcheck = ansible_module.params_get("dictcheck")
|
"priority", int, allow_empty=True)
|
||||||
usercheck = ansible_module.params_get("usercheck")
|
maxfail = ansible_module.params_get_with_type_cast(
|
||||||
gracelimit = ansible_module.params_get("gracelimit")
|
"maxfail", int, allow_empty=True)
|
||||||
|
failinterval = ansible_module.params_get_with_type_cast(
|
||||||
|
"failinterval", int, allow_empty=True)
|
||||||
|
lockouttime = ansible_module.params_get_with_type_cast(
|
||||||
|
"lockouttime", int, allow_empty=True)
|
||||||
|
maxrepeat = ansible_module.params_get_with_type_cast(
|
||||||
|
"maxrepeat", int, allow_empty=True)
|
||||||
|
maxsequence = ansible_module.params_get_with_type_cast(
|
||||||
|
"maxsequence", int, allow_empty=True)
|
||||||
|
dictcheck = ansible_module.params_get_with_type_cast(
|
||||||
|
"dictcheck", bool, allow_empty=True)
|
||||||
|
usercheck = ansible_module.params_get_with_type_cast(
|
||||||
|
"usercheck", bool, allow_empty=True)
|
||||||
|
gracelimit = ansible_module.params_get_with_type_cast(
|
||||||
|
"gracelimit", int, allow_empty=True)
|
||||||
|
|
||||||
# state
|
# state
|
||||||
state = ansible_module.params_get("state")
|
state = ansible_module.params_get("state")
|
||||||
@@ -336,41 +350,6 @@ def main():
|
|||||||
|
|
||||||
ansible_module.params_fail_used_invalid(invalid, state)
|
ansible_module.params_fail_used_invalid(invalid, state)
|
||||||
|
|
||||||
# Ensure parameter values are valid and have proper type.
|
|
||||||
def int_or_empty_param(value, param):
|
|
||||||
if value is not None and value != "":
|
|
||||||
try:
|
|
||||||
value = int(value)
|
|
||||||
except ValueError:
|
|
||||||
ansible_module.fail_json(
|
|
||||||
msg="Invalid value '%s' for argument '%s'" % (value, param)
|
|
||||||
)
|
|
||||||
return value
|
|
||||||
|
|
||||||
maxlife = int_or_empty_param(maxlife, "maxlife")
|
|
||||||
minlife = int_or_empty_param(minlife, "minlife")
|
|
||||||
history = int_or_empty_param(history, "history")
|
|
||||||
minclasses = int_or_empty_param(minclasses, "minclasses")
|
|
||||||
minlength = int_or_empty_param(minlength, "minlength")
|
|
||||||
priority = int_or_empty_param(priority, "priority")
|
|
||||||
maxfail = int_or_empty_param(maxfail, "maxfail")
|
|
||||||
failinterval = int_or_empty_param(failinterval, "failinterval")
|
|
||||||
lockouttime = int_or_empty_param(lockouttime, "lockouttime")
|
|
||||||
maxrepeat = int_or_empty_param(maxrepeat, "maxrepeat")
|
|
||||||
maxsequence = int_or_empty_param(maxsequence, "maxsequence")
|
|
||||||
gracelimit = int_or_empty_param(gracelimit, "gracelimit")
|
|
||||||
|
|
||||||
def bool_or_empty_param(value, param): # pylint: disable=R1710
|
|
||||||
if value is None or value == "":
|
|
||||||
return value
|
|
||||||
try:
|
|
||||||
return boolean(value)
|
|
||||||
except TypeError as terr:
|
|
||||||
ansible_module.fail_json(msg="Param '%s': %s" % (param, str(terr)))
|
|
||||||
|
|
||||||
dictcheck = bool_or_empty_param(dictcheck, "dictcheck")
|
|
||||||
usercheck = bool_or_empty_param(usercheck, "usercheck")
|
|
||||||
|
|
||||||
# Ensure gracelimit has proper limit.
|
# Ensure gracelimit has proper limit.
|
||||||
if gracelimit:
|
if gracelimit:
|
||||||
if gracelimit < -1:
|
if gracelimit < -1:
|
||||||
|
|||||||
Reference in New Issue
Block a user