From 8237c07f973eb8e551da247a530c880d42c56a9e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 2 Jan 2025 15:32:05 +0100 Subject: [PATCH] Finishing evaluating 389ds automember plugin configuration. --- lib/ansible/ds389_plugins_info.py | 140 +++++++++++++++++++++++++++--- 1 file changed, 128 insertions(+), 12 deletions(-) diff --git a/lib/ansible/ds389_plugins_info.py b/lib/ansible/ds389_plugins_info.py index bcc7d64..413ceeb 100644 --- a/lib/ansible/ds389_plugins_info.py +++ b/lib/ansible/ds389_plugins_info.py @@ -75,6 +75,18 @@ class Ds389PluginsInfo(object): re_plugin_version = re.compile(r'^nsslapd-pluginVersion:\s+(.*)', re.IGNORECASE) re_enabled = re.compile(r'^nsslapd-pluginEnabled:\s+(.*)', re.IGNORECASE) + re_am_default_group = re.compile(r'^autoMemberDefaultGroup:\s+(.*)', re.IGNORECASE) + re_am_grouping_attr = re.compile(r'^autoMemberGroupingAttr:\s+(.*)', re.IGNORECASE) + re_am_scope = re.compile(r'^autoMemberScope:\s+(.*)', re.IGNORECASE) + re_am_filter = re.compile(r'^autoMemberFilter:\s+(.*)', re.IGNORECASE) + + re_am_no_regexes = re.compile(r'^No\s+Automember\s+regexes\s+were\s+found', re.IGNORECASE) + re_am_regex_excl = re.compile(r'^autoMemberExclusiveRegex:\s+(.*)', re.IGNORECASE) + re_am_regex_incl = re.compile(r'^autoMemberInclusiveRegex:\s+(.*)', re.IGNORECASE) + re_am_regex_target = re.compile(r'^autoMemberTargetGroup:\s+(.*)', re.IGNORECASE) + + am_key = 'automember' + # -------------------------------------------------------------------------- def __init__(self): """Initialize the Ds389LoggingInfo object.""" @@ -131,14 +143,13 @@ class Ds389PluginsInfo(object): if proc.returncode: return - key = 'automember' re_processmodifyops = re.compile(r'^automemberProcessModifyOps:\s+(.*)', re.IGNORECASE) - if key not in self.result: - self.result[key] = {} + if self.am_key not in self.result: + self.result[self.am_key] = {} - if 'definition' not in self.result[key]: - self.result[key]['definition'] = {} + if 'definition' not in self.result[self.am_key]: + self.result[self.am_key]['definition'] = {} for line in proc.stdout.splitlines(): line = line.strip() @@ -147,22 +158,22 @@ class Ds389PluginsInfo(object): m = self.re_cn.match(line) if m: - self.result[key]['cn'] = m.group(1) + self.result[self.am_key]['cn'] = m.group(1) continue m = self.re_plugin_version.match(line) if m: - self.result[key]['plugin_version'] = m.group(1) + self.result[self.am_key]['plugin_version'] = m.group(1) continue m = self.re_enabled.match(line) if m: - self.result[key]['enabled'] = self.mangle_value(m.group(1)) + self.result[self.am_key]['enabled'] = self.mangle_value(m.group(1)) continue m = re_processmodifyops.match(line) if m: - self.result[key]['process_modify_ops'] = self.mangle_value(m.group(1)) + self.result[self.am_key]['process_modify_ops'] = self.mangle_value(m.group(1)) continue self._get_automember_definitions() @@ -178,7 +189,6 @@ class Ds389PluginsInfo(object): if proc.returncode: return - key = 'automember' re_no_automember = re.compile( r'^No\s+Automember\s+definitions\s+were\s+found', re.IGNORECASE) @@ -190,8 +200,114 @@ class Ds389PluginsInfo(object): if re_no_automember.match(def_name): break - if def_name not in self.result[key]['definition']: - self.result[key]['definition'][def_name] = {} + if def_name not in self.result[self.am_key]['definition']: + self.result[self.am_key]['definition'][def_name] = {} + + self._get_automember_definition(def_name) + + # -------------------------------------------------------------------------- + def _get_automember_definition(self, def_name): + + proc = run( + [self.cmd, self.instance, 'plugin', 'automember', 'definition', def_name, 'show'], + capture_output=True, encoding=self.encoding) + + if proc.stderr: + module.warn(proc.stderr) + if proc.returncode: + return + + if 'regex' not in self.result[self.am_key]['definition'][def_name]: + self.result[self.am_key]['definition'][def_name]['regex'] = {} + + for line in proc.stdout.splitlines(): + line = line.strip() + if not line: + continue + + m = self.re_am_default_group.match(line) + if m: + self.result[self.am_key]['definition'][def_name]['default_group'] = m.group(1) + continue + + m = self.re_am_grouping_attr(line) + if m: + self.result[self.am_key]['definition'][def_name]['grouping_attribute'] = m.group(1) + continue + + m = self.re_am_scope(line) + if m: + self.result[self.am_key]['definition'][def_name]['scope'] = m.group(1) + continue + + m = self.re_am_filter(line) + if m: + self.result[self.am_key]['definition'][def_name]['re_am_filter'] = m.group(1) + continue + + self._get_automember_regexes(def_name) + + # -------------------------------------------------------------------------- + def _get_automember_regexes(self, def_name): + + proc = run( + [self.cmd, self.instance, 'plugin', 'automember', 'list', 'regexes', def_name], + capture_output=True, encoding=self.encoding) + if proc.stderr: + module.warn(proc.stderr) + if proc.returncode: + return + + for re_name in proc.stdout.splitlines(): + re_name = def_name.strip() + if not re_name: + continue + + if self.re_am_no_regexes.match(re_name): + break + + if re_name not in self.result[self.am_key]['definition']: + self.result[self.am_key]['definition'][def_name]['regex'][re_name] = {} + + self._get_automember_regex(def_name, re_name) + + # -------------------------------------------------------------------------- + def _get_automember_regex(self, def_name, re_name): + + proc = run( + [self.cmd, self.instance, 'plugin', 'automember', 'definition', + 'regex', re_name, 'show'], + capture_output=True, encoding=self.encoding) + + if proc.stderr: + module.warn(proc.stderr) + if proc.returncode: + return + + regex = self.result[self.am_key]['definition'][def_name]['regex'][re_name] + + regex['exclusive'] = [] + regex['inclusive'] = [] + regex['target_group'] = None + + for line in proc.stdout.splitlines(): + line = line.strip() + if not line: + continue + + m = self.re_am_regex_excl.match(line) + if m: + regex['exclusive'].append(m.group(1)) + continue + + m = self.re_am_regex_incl.match(line) + if m: + regex['inclusive'].append(m.group(1)) + continue + + m = self.re_am_regex_target.match(line) + if m: + regex['target_group'] = m.group(1) # -------------------------------------------------------------------------- def get_memberof(self): -- 2.39.5