From 1a834fbd256280ab22d08791f98c1f63fa57e672 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 21 Oct 2022 17:16:02 +0200 Subject: [PATCH] Adding and using lib/pp_admintools/config/mirror_ldap.py --- etc/mirror-ldap.yaml | 10 +++ lib/pp_admintools/app/mirror_ldap.py | 7 +- lib/pp_admintools/config/mirror_ldap.py | 98 +++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 etc/mirror-ldap.yaml create mode 100644 lib/pp_admintools/config/mirror_ldap.py diff --git a/etc/mirror-ldap.yaml b/etc/mirror-ldap.yaml new file mode 100644 index 0000000..9e95101 --- /dev/null +++ b/etc/mirror-ldap.yaml @@ -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 diff --git a/lib/pp_admintools/app/mirror_ldap.py b/lib/pp_admintools/app/mirror_ldap.py index 597cd51..4206c63 100644 --- a/lib/pp_admintools/app/mirror_ldap.py +++ b/lib/pp_admintools/app/mirror_ldap.py @@ -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 index 0000000..7fc16ae --- /dev/null +++ b/lib/pp_admintools/config/mirror_ldap.py @@ -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 -- 2.39.5