]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding additional optional parameters to methods in lib/pp_admintools/app/ldap.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 11:56:44 +0000 (13:56 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 11:56:44 +0000 (13:56 +0200)
lib/pp_admintools/app/ldap.py

index 32017487b7e7e6cef98b637202f44d9da02cc64d..f623a5669a08f28296b1bb19092afd709b90c2bb 100644 (file)
@@ -45,7 +45,7 @@ from ..config.ldap import DEFAULT_TIMEOUT
 from ..config.ldap import LdapConfiguration, LdapConnectionInfo
 from ..xlate import XLATOR, format_list
 
-__version__ = '0.11.5'
+__version__ = '0.11.6'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -772,7 +772,7 @@ class BaseLdapApplication(BaseDPXApplication):
             del self.ldap_server[inst]
 
     # -------------------------------------------------------------------------
-    def get_all_entries(self, inst, base_dn=None, ldap_filter=None, attributes=None):
+    def get_all_entries(self, inst, base_dn=None, ldap_filter=None, attributes=None, scope=None):
         """
         Get all LDAP entries bellow the given BaseDN and the given LDAP filter.
 
@@ -782,6 +782,8 @@ class BaseLdapApplication(BaseDPXApplication):
         """
         connect_info = self.cfg.ldap_connection[inst]
         ldap = self.ldap_connection[inst]
+        if scope is None:
+            scope = SUBTREE
 
         result = {}
 
@@ -800,7 +802,7 @@ class BaseLdapApplication(BaseDPXApplication):
             LOG.debug(msg)
 
         req_status, req_result, req_response, req_whatever = ldap.search(
-            search_base=base_dn, search_scope=SUBTREE, attributes=attributes,
+            search_base=base_dn, search_scope=scope, attributes=attributes,
             search_filter=ldap_filter, time_limit=self.cfg.ldap_timeout)
 
         if req_status:
@@ -832,11 +834,14 @@ class BaseLdapApplication(BaseDPXApplication):
         return result
 
     # -------------------------------------------------------------------------
-    def get_all_entry_dns(self, inst, ldap_filter=None):
+    def get_all_entry_dns(self, inst, ldap_filter=None, base_dn=None, scope=None):
         """Get DNs of all entries in the given LDAP instance and sort them."""
         connect_info = self.cfg.ldap_connection[inst]
-        base_dn = connect_info.base_dn
+        if not base_dn:
+            base_dn = connect_info.base_dn
         ldap = self.ldap_connection[inst]
+        if scope is None:
+            scope = SUBTREE
 
         result = []