Skip to content

Commit

Permalink
[pfsense] Add generic get_refid() method and get_certref/get_crlref
Browse files Browse the repository at this point in the history
  • Loading branch information
opoplawski committed Jan 5, 2024
1 parent 1f30825 commit b467346
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions plugins/module_utils/pfsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit b467346

Please sign in to comment.