]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding and using lib/pp_admintools/config/mirror_ldap.py
authorFrank Brehm <frank@brehm-online.com>
Fri, 21 Oct 2022 15:16:02 +0000 (17:16 +0200)
committerFrank Brehm <frank@brehm-online.com>
Fri, 21 Oct 2022 15:16:02 +0000 (17:16 +0200)
etc/mirror-ldap.yaml [new file with mode: 0644]
lib/pp_admintools/app/mirror_ldap.py
lib/pp_admintools/config/mirror_ldap.py [new file with mode: 0644]

diff --git a/etc/mirror-ldap.yaml b/etc/mirror-ldap.yaml
new file mode 100644 (file)
index 0000000..9e95101
--- /dev/null
@@ -0,0 +1,10 @@
+---
+
+mirror-ldap:
+  keep-entries:
+    dpx-dev:
+      - 'cn=Replication monitor,o=isp'
+    spk-stage:
+      - 'cn=Replication monitor,dc=spk,dc=pixelpark,dc=net'
+
+# vim: filetype=yaml
index 597cd51037208bb6cf013d70c43d8e3071ebd718..4206c63b82f3c37f050db451f52433ca5d890dd5 100644 (file)
@@ -27,6 +27,8 @@ from fb_tools.collections import CIDict, CIStringSet
 
 from ..xlate import XLATOR
 
+from ..config.mirror_ldap import MirrorLdapConfiguration
+
 # from .ldap import LdapAppError, FatalLDAPError
 from .ldap import LdapAppError
 from .ldap import BaseLdapApplication
@@ -34,7 +36,7 @@ from .ldap import BaseLdapApplication
 from ..argparse_actions import NonNegativeItegerOptionAction
 from ..argparse_actions import LimitedFloatOptionAction
 
-__version__ = '0.4.2'
+__version__ = '0.5.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -94,7 +96,8 @@ class MirrorLdapApplication(BaseLdapApplication):
         self._force_desc_msg = _("Do not execute a countdown before starting the application.")
 
         super(MirrorLdapApplication, self).__init__(
-            appname=appname, description=desc, base_dir=base_dir, initialized=False)
+            appname=appname, description=desc, base_dir=base_dir,
+            cfg_class=MirrorLdapConfiguration, initialized=False)
 
         self.initialized = True
 
diff --git a/lib/pp_admintools/config/mirror_ldap.py b/lib/pp_admintools/config/mirror_ldap.py
new file mode 100644 (file)
index 0000000..7fc16ae
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@summary: A module for providing a configuration for the mirror-ldap application.
+
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2022 by Frank Brehm, Berlin
+"""
+from __future__ import absolute_import
+
+# Standard module
+import logging
+# import copy
+# import re
+
+# Third party modules
+from fb_tools.common import is_sequence, pp
+from fb_tools.multi_config import DEFAULT_ENCODING
+
+# Own modules
+from .. import DEFAULT_CONFIG_DIR
+
+from .ldap import LdapConfigError, LdapConfiguration
+
+from ..xlate import XLATOR
+
+__version__ = '0.1.0'
+LOG = logging.getLogger(__name__)
+
+_ = XLATOR.gettext
+
+
+# =============================================================================
+class MirrorLdapConfigError(LdapConfigError):
+    """Error class for configuration errors of the mirror-ldap application."""
+
+    pass
+
+
+# =============================================================================
+class MirrorLdapConfiguration(LdapConfiguration):
+    """A class for configuring the mirror-ldap application."""
+
+    # -------------------------------------------------------------------------
+    def __init__(
+        self, appname=None, verbose=0, version=__version__, base_dir=None,
+            append_appname_to_stems=True, additional_stems=None, config_dir=DEFAULT_CONFIG_DIR,
+            additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
+            ensure_privacy=False, use_chardet=True, initialized=False):
+
+        self.entries_keep = {}
+        self.transform = {}
+
+        add_stems = []
+        if additional_stems:
+            if is_sequence(additional_stems):
+                for stem in additional_stems:
+                    add_stems.append(stem)
+            else:
+                add_stems.append(additional_stems)
+
+        if 'mirror-ldap' not in add_stems:
+            add_stems.append('mirror-ldap')
+
+        super(MirrorLdapConfiguration, self).__init__(
+            appname=appname, verbose=verbose, version=version, base_dir=base_dir,
+            append_appname_to_stems=append_appname_to_stems, config_dir=config_dir,
+            additional_stems=add_stems, additional_config_file=additional_config_file,
+            additional_cfgdirs=additional_cfgdirs, encoding=encoding, use_chardet=use_chardet,
+            ensure_privacy=ensure_privacy, initialized=False,
+        )
+
+        self.initialized = True
+
+    # -------------------------------------------------------------------------
+    def eval_section(self, section_name):
+
+        sn = section_name.lower()
+        section = self.cfg[section_name]
+
+        if self.verbose > 1:
+            LOG.debug(_("Evaluating configuration section {sn!r} ...").format(sn=sn))
+
+        if self.verbose > 3:
+            LOG.debug("Section:\n" + pp(section))
+
+        super(MirrorLdapConfiguration, self).eval_section(section_name)
+
+
+# =============================================================================
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list