From 1779eff10e4cea718da0b7f51be472461cf12c74 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 1 Feb 2024 12:13:59 +0100 Subject: [PATCH] Rewriting specialized search methods to use the general search() method. --- lib/pp_admintools/app/ldap.py | 74 ++++++++--------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 23c8c93..4166013 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -61,7 +61,7 @@ from ..errors import DpxLdapSessionError from ..errors import DpxWriteLdapItemError from ..xlate import XLATOR, format_list -__version__ = '1.3.5' +__version__ = '1.3.6' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -1811,21 +1811,11 @@ class BaseLdapApplication(BaseDPXApplication): uri=connect_info.url, bdn=base_dn, fltr=ldap_filter) LOG.debug(msg) - if inst not in self.ldap_connection: - self.connect_instance(inst) - ldap = self.ldap_connection[inst] - - try: - req_status, req_result, req_response, req_whatever = ldap.search( - search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter, - get_operational_attributes=False, attributes=attributes, - time_limit=self.cfg.ldap_timeout) - finally: - if not self.single_session: - self.disconnect_instance(inst) + (search_status, search_result, search_response) = self.search( + inst=inst, search_base=base_dn, attributes=attributes, scope=SUBTREE) - if req_status: - for entry in req_response: + if search_status: + for entry in search_response: if self.verbose > 4: LOG.debug(_('Got a response entry:') + ' ' + pp(entry)) result.append(entry['dn']) @@ -1852,21 +1842,11 @@ class BaseLdapApplication(BaseDPXApplication): uri=connect_info.url, bdn=base_dn, fltr=ldap_filter) LOG.debug(msg) - if inst not in self.ldap_connection: - self.connect_instance(inst) - ldap = self.ldap_connection[inst] - - try: - req_status, req_result, req_response, req_whatever = ldap.search( - search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter, - get_operational_attributes=False, attributes=attributes, - time_limit=self.cfg.ldap_timeout) - finally: - if not self.single_session: - self.disconnect_instance(inst) + (search_status, search_result, search_response) = self.search( + inst=inst, search_base=base_dn, attributes=attributes, scope=SUBTREE) - if req_status: - for entry in req_response: + if search_status: + for entry in search_response: if self.verbose > 4: LOG.debug(_('Got a response entry:') + ' ' + pp(entry)) result.append(entry['dn']) @@ -1893,21 +1873,11 @@ class BaseLdapApplication(BaseDPXApplication): uri=connect_info.url, bdn=base_dn, fltr=ldap_filter) LOG.debug(msg) - if inst not in self.ldap_connection: - self.connect_instance(inst) - ldap = self.ldap_connection[inst] - - try: - req_status, req_result, req_response, req_whatever = ldap.search( - search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter, - get_operational_attributes=False, attributes=attributes, - time_limit=self.cfg.ldap_timeout) - finally: - if not self.single_session: - self.disconnect_instance(inst) + (search_status, search_result, search_response) = self.search( + inst=inst, search_base=base_dn, attributes=attributes, scope=SUBTREE) - if req_status: - for entry in req_response: + if search_status: + for entry in search_response: if self.verbose > 4: LOG.debug(_('Got a response entry:') + ' ' + pp(entry)) result.append(entry['dn']) @@ -1934,21 +1904,11 @@ class BaseLdapApplication(BaseDPXApplication): uri=connect_info.url, bdn=base_dn, fltr=ldap_filter) LOG.debug(msg) - if inst not in self.ldap_connection: - self.connect_instance(inst) - ldap = self.ldap_connection[inst] - - try: - req_status, req_result, req_response, req_whatever = ldap.search( - search_base=base_dn, search_scope=SUBTREE, search_filter=ldap_filter, - get_operational_attributes=False, attributes=attributes, - time_limit=self.cfg.ldap_timeout) - finally: - if not self.single_session: - self.disconnect_instance(inst) + (search_status, search_result, search_response) = self.search( + inst=inst, search_base=base_dn, attributes=attributes, scope=SUBTREE) - if req_status: - for entry in req_response: + if search_status: + for entry in search_response: if self.verbose > 4: LOG.debug(_('Got a response entry:') + ' ' + pp(entry)) result.append(entry['dn']) -- 2.39.5