-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle data type or empty string in module_utils #1143
Conversation
plugins/modules/ipapwpolicy.py
Outdated
maxlife = ansible_module.params_get_tipe( | ||
"maxlife", int, allow_empty_string=True) | ||
minlife = ansible_module.params_get_tipe( | ||
"minlife", int, allow_empty_string=True) | ||
history = ansible_module.params_get_tipe( | ||
"history", int, allow_empty_string=True) | ||
minclasses = ansible_module.params_get_tipe( | ||
"minclasses", int, allow_empty_string=True) | ||
minlength = ansible_module.params_get_tipe( | ||
"minlength", int, allow_empty_string=True) | ||
priority = ansible_module.params_get_tipe( | ||
"priority", int, allow_empty_string=True) | ||
maxfail = ansible_module.params_get_tipe( | ||
"maxfail", int, allow_empty_string=True) | ||
failinterval = ansible_module.params_get_tipe( | ||
"failinterval", int, allow_empty_string=True) | ||
lockouttime = ansible_module.params_get_tipe( | ||
"lockouttime", int, allow_empty_string=True) | ||
maxrepeat = ansible_module.params_get_tipe( | ||
"maxrepeat", int, allow_empty_string=True) | ||
maxsequence = ansible_module.params_get_tipe( | ||
"maxsequence", int, allow_empty_string=True) | ||
dictcheck = ansible_module.params_get_tipe( | ||
"dictcheck", bool, allow_empty_string=True) | ||
usercheck = ansible_module.params_get_tipe( | ||
"usercheck", bool, allow_empty_string=True) | ||
gracelimit = ansible_module.params_get_tipe( | ||
"gracelimit", int, allow_empty_string=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these should be ansible_module.params_get_type(..)
. About: allow_empty_string=True
this is the wrong parameter right now. The current allow_empty_string
needs to be renamed to something like allow_empty_list_item
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
8d7c2ba
to
1cb207e
Compare
1cb207e
to
1d55bc5
Compare
1d55bc5
to
8f8f976
Compare
8f8f976
to
c1efee7
Compare
c1efee7
to
0f11484
Compare
@@ -497,6 +497,49 @@ def module_params_get_lowercase(module, name, allow_empty_list_item=False): | |||
return value | |||
|
|||
|
|||
def module_params_get_type( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module_params_get_type
is misleading. Maybe something like module_params_get_with_type
or module_params_get_converted
or module_params_get_convert_to_type
would be better.
@@ -1072,6 +1115,28 @@ def params_get_lowercase(self, name, allow_empty_list_item=False): | |||
""" | |||
return module_params_get_lowercase(self, name, allow_empty_list_item) | |||
|
|||
def params_get_type( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
The parameter 'allow_empty_string' in 'module_params_get' is used to allow an item in a list to be an empty string. The problem is that the naming is misleading, as it is checking a list item rather than a string. This patch rename the parameter to 'allow_empty_list_item' so that it more clearly refers to list itens instead of standalone strings, and do not collide with future parameters that may test for empty strings which are not part of lists.
0f11484
to
a8d0171
Compare
a8d0171
to
eadab1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Downstream tests are passed
@t-woerner what do you think about calling the method "params_get_with_type_cast"? Not only this is more explicitly tells what the method is doing, but it also alows for new usage, such as I have the second example in a local "playground branch", and I'm getting fond of the solution for ensuring idempotence in the face of different value types. (Note: I converted the PR to "draft" so that it is not merged before we are aligned on the method name.) |
39cbf96
to
7e0e1d1
Compare
Some parameters, in modules, have a specific data type, but allow the use of an empty string to clear the parameter. By providing a method to retrieve the parameter with the correct data type, or optionally an empty string, allows for consistency of parameter handling between different modules.
Use the commom parameter type handling method for parameters that accept a value or an empty string.
Use the commom parameter type handling method for parameters that accept a value or an empty string.
Use the commom parameter type handling method for parameters that accept a value or an empty string.
7e0e1d1
to
34973c0
Compare
As discussed offline, I renamed the new method/function to |
Some parameters, in modules, have a specific data type, but allow the use of an empty string to clear the parameter.
By providing a method to retrieve the parameter with the correct data type, or optionally an empty string, allows for consistency of parameter handling between different modules.
Currently,
ipapwpolicy
andipaidoverrideuser
requires such method, and both were modified to use the module_utils implementation.