freeipa / ansible-freeipa

Ansible roles and modules for FreeIPA
GNU General Public License v3.0
489 stars 232 forks source link

Handle data type or empty string in module_utils #1143

Closed rjeffman closed 8 months ago

rjeffman commented 11 months ago

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 and ipaidoverrideuser requires such method, and both were modified to use the module_utils implementation.

rjeffman commented 9 months ago

@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 params_get_with_type_cast("aduser", ad_user_type), or params_get_with_type_cast("service", list_of(service(ipa_realm)).

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.)

rjeffman commented 8 months ago

As discussed offline, I renamed the new method/function to *_get_with_type_cast, as it explicity says what it is doing, specially in the cases used by PR #1190 (which is based on these changes)