From: Frank Brehm Date: Mon, 5 Sep 2022 14:36:37 +0000 (+0200) Subject: Fixing lib/pp_admintools/ldap_app.py and lib/pp_admintools/ldap_config.py X-Git-Tag: 0.5.0^2~2^2~24 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=fd30d7e9366a827981880c8556e4ee70333d7c9d;p=pixelpark%2Fpp-admin-tools.git Fixing lib/pp_admintools/ldap_app.py and lib/pp_admintools/ldap_config.py --- diff --git a/lib/pp_admintools/ldap_app.py b/lib/pp_admintools/ldap_app.py index 3e55314..d88de65 100644 --- a/lib/pp_admintools/ldap_app.py +++ b/lib/pp_admintools/ldap_app.py @@ -36,7 +36,7 @@ from .ldap_config import LdapConnectionInfo, LdapConfiguration # rom .ldap_config import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from .ldap_config import DEFAULT_TIMEOUT, MAX_TIMEOUT -__version__ = '0.1.2' +__version__ = '0.1.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -235,7 +235,7 @@ class BaseLdapApplication(FbConfigApplication): ldap_bind_dn = LdapConfiguration.default_bind_dn ldap_group.add_argument( - '-h', '--ldap-host', metavar=_("HOST"), dest="ldap_host", + '-H', '--ldap-host', metavar=_("HOST"), dest="ldap_host", help=_( "Hostname or address of the LDAP server to use. Default: {!r}").format( ldap_host), diff --git a/lib/pp_admintools/ldap_config.py b/lib/pp_admintools/ldap_config.py index 583be29..42bd061 100644 --- a/lib/pp_admintools/ldap_config.py +++ b/lib/pp_admintools/ldap_config.py @@ -30,7 +30,7 @@ from . import MAX_PORT_NUMBER, DEFAULT_CONFIG_DIR from .xlate import XLATOR -__version__ = '0.2.4' +__version__ = '0.2.5' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -69,12 +69,16 @@ class LdapConnectionInfo(FbBaseObject): appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False) - self.host = host + if host is not None: + self.host = host self.use_ldaps = use_ldaps self.port = port - self.base_dn = base_dn - self.bind_dn = bind_dn - self.bind_pw = bind_pw + if base_dn is not None: + self.base_dn = base_dn + if bind_dn is not None: + self.bind_dn = bind_dn + if bind_pw is not None: + self.bind_pw = bind_pw if initialized: self.initialized = True @@ -345,7 +349,11 @@ class LdapConfiguration(BaseMultiConfig): section = self.cfg[section_name] if sn == 'ldap': + LOG.debug(_("Evaluating LDAP config ...")) + for key in section.keys(): + if self.verbose > 1: + LOG.debug(_("Evaluating LDAP section {!r} ...").format(key)) sub = section[key] if key.lower().strip() == 'timeout': self._eval_ldap_timeout(sub) @@ -381,6 +389,10 @@ class LdapConfiguration(BaseMultiConfig): # ------------------------------------------------------------------------- def _eval_ldap_connection(self, connection_name, section): + if self.verbose > 2: + msg = _("Reading configuration of LDAP instance {!r} ...").format(connection_name) + LOG.debug(msg) + connection = LdapConnectionInfo( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, initialized=False) @@ -418,6 +430,7 @@ class LdapConfiguration(BaseMultiConfig): LOG.error(msg) continue connection.port = port + continue if self.re_ldap_base_dn_key.match(key): if value.strip(): @@ -431,7 +444,7 @@ class LdapConfiguration(BaseMultiConfig): connection.bind_dn = value continue - if self.re_ldap_bind_pw.match(key): + if self.re_ldap_bind_pw_key.match(key): connection.bind_pw = value continue