From b467346a86876abe8ab1bb035393aa0eab118525 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Thu, 4 Jan 2024 18:53:59 -0700 Subject: [PATCH] [pfsense] Add generic get_refid() method and get_certref/get_crlref --- plugins/module_utils/pfsense.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/module_utils/pfsense.py b/plugins/module_utils/pfsense.py index 2edc1d34..7a478ab5 100644 --- a/plugins/module_utils/pfsense.py +++ b/plugins/module_utils/pfsense.py @@ -20,6 +20,7 @@ from tempfile import mkstemp +# Return an element in node, but return an empty element instead of None if not found def xml_find(node, elt): res = node.find(elt) if res is None: @@ -342,17 +343,29 @@ def element_to_dict(src_elt): res[elt.tag] = value return res + def get_refid(self, node, name): + """ get refid of name in specific nodes """ + elt = self.find_elt(node, name) + if elt is not None: + return xml_find(elt, 'refid').text + else: + return None + def get_caref(self, name): """ get CA refid for name """ # global is a special case if name == 'global': return 'global' - # Otherwise search for added CAs - cas = self.get_elements('ca') - for elt in cas: - if xml_find(elt, 'descr').text == name: - return xml_find(elt, 'refid').text - return None + # Otherwise search the ca elements + return self.get_refid('ca', name) + + def get_certref(self, name): + """ get Cert refid for name """ + return self.get_refid('cert', name) + + def get_crlref(self, name): + """ get CRL refid for name """ + return self.get_refid('crl', name) @staticmethod def get_username():