]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding evluation of attr-uniq entries in lib/ansible/ds389_plugins_info.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 2 Jan 2025 15:57:34 +0000 (16:57 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 2 Jan 2025 15:57:34 +0000 (16:57 +0100)
lib/ansible/ds389_plugins_info.py

index aa4d36f3f6c006d65f47c6e517d1f9ee57b83dfa..8885d52427d0b57465e97c4cb7b858f8ff436865 100644 (file)
@@ -86,7 +86,15 @@ class Ds389PluginsInfo(object):
     re_am_regex_incl = re.compile(r'^autoMemberInclusiveRegex:\s+(.*)', re.IGNORECASE)
     re_am_regex_target = re.compile(r'^autoMemberTargetGroup:\s+(.*)', re.IGNORECASE)
 
+    re_au_attribute_name = re.compile(r'^uniqueness-attribute-name:\s+(.*)', re.IGNORECASE)
+    re_au_subtree = re.compile(r'^uniqueness-subtrees:\s+(.*)', re.IGNORECASE)
+    re_au_across_all_subtrees = re.compile(
+        r'^uniqueness-across-all-subtrees:\s+(.*)', re.IGNORECASE)
+    re_au_top_entry_oc = re.compile(r'^uniqueness-top-entry-oc:\s+(.*)', re.IGNORECASE)
+    re_au_subtree_entries_oc = re.compile(r'^uniqueness-subtree-entries-oc:\s+(.*)', re.IGNORECASE)
+
     am_key = 'automember'
+    au_key = 'attr_iniq'
 
     # --------------------------------------------------------------------------
     def __init__(self):
@@ -112,6 +120,7 @@ class Ds389PluginsInfo(object):
         self.get_referint()
         self.get_root_dn_access()
         self.get_account_policy()
+        self.get_attr_uniq()
 
         return self.result
 
@@ -394,6 +403,97 @@ class Ds389PluginsInfo(object):
                 self.result[key]['auto_add_oc'] = m.group(1)
                 continue
 
+    # --------------------------------------------------------------------------
+    def get_attr_uniq(self):
+        """Get configuration of attr-uniq plugin entries."""
+        cmd = [self.cmd, self.instance, 'plugin', 'attr-uniq', 'list']
+        proc = run(cmd, capture_output=True, encoding=self.encoding)
+        if proc.stderr:
+            msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr
+            module.warn(msg)
+        if proc.returncode:
+            return
+
+        re_no_attr_uniq = re.compile(r'^No\s+Attr', re.IGNORECASE)
+
+        if self.au_key not in self.result:
+            self.result[self.au_key] = {}
+
+        for entry_name in proc.stdout.splitlines():
+            entry_name = entry_name.strip()
+            if not entry_name:
+                continue
+
+            if re_no_attr_uniq.match(entry_name):
+                break
+
+            if entry_name not in self.result[self.au_key]:
+                self.result[self.au_key][entry_name] = {}
+
+        for entry_name in self.result[self.au_key].keys():
+            self._get_attr_uniq_entry(entry_name)
+
+    # --------------------------------------------------------------------------
+    def _get_attr_uniq_entry(self, entry_name):
+
+        cmd = [self.cmd, self.instance, 'plugin', 'attr-uniq', 'show', entry_name]
+        proc = run(cmd, capture_output=True, encoding=self.encoding)
+        if proc.stderr:
+            msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr
+            module.warn(msg)
+        if proc.returncode:
+            return
+
+        for line in proc.stdout.splitlines():
+            line = line.strip()
+            if not line:
+                continue
+
+            m = self.re_cn.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['cn'] = m.group(1)
+                continue
+
+            m = self.re_plugin_version.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['plugin_version'] = m.group(1)
+                continue
+
+            m = self.re_enabled.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['enabled'] = self.mangle_value(m.group(1))
+                continue
+
+            m = self.re_au_attribute_name.match(line)
+            if m:
+                if 'attribute_name' not in self.result[self.au_key][entry_name]:
+                    self.result[self.au_key][entry_name]['attribute_name'] = []
+                self.result[self.au_key][entry_name]['attribute_name'].append(m.group(1))
+                continue
+
+            m = self.re_au_subtree.match(line)
+            if m:
+                if 'subtree' not in self.result[self.au_key][entry_name]:
+                    self.result[self.au_key][entry_name]['subtree'] = []
+                self.result[self.au_key][entry_name]['subtree'].append(m.group(1))
+                continue
+
+            m = self.re_au_across_all_subtrees.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['across_all_subtrees'] = self.mangle_value(
+                    m.group(1))
+                continue
+
+            m = self.re_au_top_entry_oc.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['top_entry_oc'] = m.group(1)
+                continue
+
+            m = self.re_au_subtree_entries_oc.match(line)
+            if m:
+                self.result[self.au_key][entry_name]['subtree_entries_oc'] = m.group(1)
+                continue
+
     # --------------------------------------------------------------------------
     def get_referint(self):
         """Get config of referential-integrity plugin."""