def read(self): known_aliases_list = map(lambda x: x.text, self._source_tree.iterfind('table/name')) self._aliases = dict() for elem in self._source_tree.iterfind('table'): alias = Alias(elem, known_aliases=known_aliases_list) self._aliases[alias.get_name()] = alias
def read(self): """ read aliases :return: None """ self._aliases = dict() alias_parameters = dict() alias_parameters['known_aliases'] = [x.text for x in self._source_tree.iterfind('table/name')] # parse general alias settings conf_general = self._source_tree.find('general') if conf_general: if conf_general.find('ssl_no_verify') is not None and conf_general.find('ssl_no_verify').text == "1": alias_parameters['ssl_no_verify'] = True # loop through aliases for elem in self._source_tree.iterfind('table'): alias = Alias(elem, **alias_parameters) self._aliases[alias.get_name()] = alias
def read(self): """ read aliases :return: None """ self._aliases = dict() external_aliases = list() alias_parameters = dict() alias_parameters['known_aliases'] = [ x.text for x in self._source_tree.iterfind('table/name') ] for line in subprocess.run(['/sbin/pfctl', '-sT'], capture_output=True, text=True).stdout.strip().split('\n'): alias_name = line.strip() if alias_name not in alias_parameters['known_aliases']: alias_parameters['known_aliases'].append(alias_name) external_aliases.append(alias_name) # parse general alias settings conf_general = self._source_tree.find('general') if conf_general: if conf_general.find( 'ssl_no_verify') is not None and conf_general.find( 'ssl_no_verify').text == "1": alias_parameters['ssl_no_verify'] = True # loop through user defined aliases for elem in self._source_tree.iterfind('table'): alias = Alias(elem, **alias_parameters) self._aliases[alias.get_name()] = alias # attach external aliases which aren't defined via the gui for alias_name in external_aliases: elem = ET.Element("table") ET.SubElement(elem, 'type').text = 'external' ET.SubElement(elem, 'name').text = alias_name ET.SubElement(elem, 'ttl').text = '1' self._aliases[alias_name] = Alias(elem, **alias_parameters)