]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Checking validity of a LDAP config entry.
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 Jan 2024 12:19:25 +0000 (13:19 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 25 Jan 2024 12:19:25 +0000 (13:19 +0100)
lib/pp_admintools/app/ldap.py
lib/pp_admintools/config/ldap.py

index 328dd681ce09c96998401c53ee8264c84b4ebff8..09e3c89b7e66a2572372f1785fdfcb8b872089b2 100644 (file)
@@ -49,7 +49,7 @@ from ..config.ldap import DEFAULT_TIMEOUT
 from ..config.ldap import LdapConfiguration, LdapConnectionInfo
 from ..xlate import XLATOR, format_list
 
-__version__ = '0.12.1'
+__version__ = '0.12.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -559,6 +559,9 @@ class BaseLdapApplication(BaseDPXApplication):
 
         instances = []
         for inst in self.cfg.ldap_connection.keys():
+            cfg = self.cfg.ldap_connection[inst]
+            if not cfg.valid:
+                continue
             if inst != self.default_default_ldap_instance:
                 instances.append(inst)
         instances.sort(key=str.lower)
@@ -578,8 +581,11 @@ class BaseLdapApplication(BaseDPXApplication):
             url = '{url}/{base}'.format(url=cfg.url, base=cfg.base_dn)
             if len(url) > max_url_len:
                 max_url_len = len(url)
-            if len(cfg.bind_dn) > max_bind_dn_len:
-                max_bind_dn_len = len(cfg.bind_dn)
+            bind_dn = cfg.bind_dn
+            if not bind_dn:
+                bind_dn = ''
+            if len(bind_dn) > max_bind_dn_len:
+                max_bind_dn_len = len(bind_dn)
 
         max_key_len += 1
 
@@ -591,8 +597,11 @@ class BaseLdapApplication(BaseDPXApplication):
         for inst in instances:
             cfg = self.cfg.ldap_connection[inst]
             url = '{url}/{base}'.format(url=cfg.url, base=cfg.base_dn)
+            bind_dn = cfg.bind_dn
+            if not bind_dn:
+                bind_dn = ''
             print(tpl.format(
-                inst=(inst + ':'), width=max_key_len, url=url, bind_dn=cfg.bind_dn,
+                inst=(inst + ':'), width=max_key_len, url=url, bind_dn=bind_dn,
                 bind_dn_l=max_bind_dn_len, url_l=max_url_len, tier=cfg.tier))
         print()
 
@@ -621,6 +630,8 @@ class BaseLdapApplication(BaseDPXApplication):
             if inst == 'default':
                 continue
             instance = self.cfg.ldap_connection[inst]
+            if not instance.valid:
+                continue
             if is_admin is not None:
                 if to_bool(is_admin) != instance.is_admin:
                     continue
index 10d478a8e284750aae071bc04fcf932cb39b221b..db61fa6eb883147628c03cef0b09ff939321d325 100644 (file)
@@ -31,7 +31,7 @@ from .. import DEFAULT_CONFIG_DIR
 from .. import MAX_PORT_NUMBER
 from ..xlate import XLATOR
 
-__version__ = '0.7.1'
+__version__ = '0.8.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -132,6 +132,7 @@ class LdapConnectionInfo(FbBaseObject):
         res['tier'] = self.tier
         res['url'] = self.url
         res['use_ldaps'] = self.use_ldaps
+        res['valid'] = self.valid
 
         if self.bind_pw:
             if self.verbose > 4:
@@ -308,6 +309,25 @@ class LdapConnectionInfo(FbBaseObject):
             return
         self._admin_dn = str(value).strip()
 
+    # -----------------------------------------------------------
+    @property
+    def valid(self):
+        """Shows, whether the current connection info is valid and usable."""
+        if not self.host:
+            return False
+        if not self.port:
+            return False
+        if not self.base_dn:
+            return False
+        if self.bind_dn:
+            if not self.bind_pw:
+                return False
+        if not self.admin_dn:
+            return False
+        if not self.initialized:
+            return False
+        return True
+
     # -------------------------------------------------------------------------
     def __repr__(self):
         """Cast the type into a string for reproduction."""