]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Simplified LDAP configuration
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 12:41:20 +0000 (13:41 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 12:41:20 +0000 (13:41 +0100)
pp_lib/ldap_app.py

index 24defa3b4e85f2b80bfb1dadd42917d511778350..33b43cde987868fb68343488c7f1cac9eb1e17b5 100644 (file)
@@ -19,7 +19,7 @@ import copy
 # ldap3 classes and objects
 from ldap3 import Server, ServerPool, Connection, Reader, Writer, ObjectDef
 # ldap3 constants
-from ldap3 import IP_V4_ONLY, IP_V4_PREFERRED, ROUND_ROBIN, AUTO_BIND_NONE, ALL_ATTRIBUTES
+from ldap3 import IP_V4_PREFERRED, ROUND_ROBIN, AUTO_BIND_NONE, ALL_ATTRIBUTES
 from ldap3 import SUBTREE
 
 from ldap3.core.exceptions import LDAPPasswordIsMandatoryError
@@ -31,7 +31,7 @@ from .common import pp, to_bool
 
 from .cfg_app import PpCfgAppError, PpConfigApplication
 
-__version__ = '0.4.8'
+__version__ = '0.4.9'
 LOG = logging.getLogger(__name__)
 
 
@@ -143,15 +143,7 @@ class PpLdapApplication(PpConfigApplication):
                 self.do_ldap_cfg(section_name, section)
 
     # -------------------------------------------------------------------------
-    def do_ldap_cfg(self, section_name, section):
-
-        if self.verbose > 2:
-            LOG.debug("Evaluating config section {n!r}:\n{s}".format(
-                n=section_name, s=pp(section)))
-
-        if self.verbose > 2:
-            LOG.debug("Evaluating config section {n!r}:\n{s}".format(
-                n=section_name, s=pp(section)))
+    def _ldap_cfg_host(self, section_name, section):
 
         got_host = False
 
@@ -168,6 +160,9 @@ class PpLdapApplication(PpConfigApplication):
                     continue
                 self.ldap_hosts.append(host)
 
+    # -------------------------------------------------------------------------
+    def _ldap_cfg_port(self, section_name, section):
+
         if 'port' in section:
             try:
                 port = int(section['port'])
@@ -181,6 +176,9 @@ class PpLdapApplication(PpConfigApplication):
                 raise PpLdapAppError(msg)
             self.ldap_port = port
 
+    # -------------------------------------------------------------------------
+    def _ldap_cfg_other(self, section_name, section):
+
         if 'ssl' in section:
             self.ldap_use_ssl = to_bool(section['ssl'])
 
@@ -204,6 +202,17 @@ class PpLdapApplication(PpConfigApplication):
             if timeout > 0:
                 self.ldap_timeout = timeout
 
+    # -------------------------------------------------------------------------
+    def do_ldap_cfg(self, section_name, section):
+
+        if self.verbose > 2:
+            LOG.debug("Evaluating config section {n!r}:\n{s}".format(
+                n=section_name, s=pp(section)))
+
+        self._ldap_cfg_host(section_name, section)
+        self._ldap_cfg_port(section_name, section)
+        self._ldap_cfg_other(section_name, section)
+
         # ----------------------
         def _get_ldap_server(host):
             return Server(