From 2205907220abc674aa624069daae2e4b7e6b4491 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Campos <seocam@redhat.com> Date: Thu, 26 Mar 2020 13:10:54 -0300 Subject: [PATCH] Fixed a bug in AnsibleFreeIPAParams When accessing an instance of AnsibleFreeIPAParams with .get the obj was by-passing the call to _afm_convert which was the primaty reason why it was created. Also the class now extends Mapping instead of dict. --- .../module_utils/ansible_freeipa_module.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 9c10135f..9e3254a3 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -52,6 +52,11 @@ import socket import base64 import six +try: + from collections.abc import Mapping # noqa +except ImportError: + from collections import Mapping # noqa + if six.PY3: unicode = str @@ -351,19 +356,28 @@ def is_ipv6_addr(ipaddr): return True -class AnsibleFreeIPAParams(dict): +class AnsibleFreeIPAParams(Mapping): def __init__(self, ansible_module): - self.update(ansible_module.params) + self.mapping = ansible_module.params self.ansible_module = ansible_module + def __getitem__(self, key): + param = self.mapping[key] + if param is not None: + return _afm_convert(param) + + def __iter__(self): + return iter(self.mapping) + + def __len__(self): + return len(self.mapping) + @property def names(self): return self.name def __getattr__(self, name): - param = self.get(name) - if param is not None: - return _afm_convert(param) + return self.get(name) class FreeIPABaseModule(AnsibleModule): -- GitLab