From 9aa9a2b682e7f736f1ed33fe20049dcff39b4d90 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 6 Feb 2018 13:41:20 +0100 Subject: [PATCH] Simplified LDAP configuration --- pp_lib/ldap_app.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pp_lib/ldap_app.py b/pp_lib/ldap_app.py index 24defa3..33b43cd 100644 --- a/pp_lib/ldap_app.py +++ b/pp_lib/ldap_app.py @@ -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( -- 2.39.5