]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Enabling overriding configures Base DN in lib/pp_admintools/app/ldap.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 21 Aug 2023 12:43:35 +0000 (14:43 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 21 Aug 2023 12:43:35 +0000 (14:43 +0200)
lib/pp_admintools/app/ldap.py

index 41e3e02338bd38397d256464145dd84c463b057f..37791809ef2486fe8a6183766d353518da096825 100644 (file)
@@ -46,7 +46,7 @@ from ..config.ldap import DEFAULT_TIMEOUT
 from ..config.ldap import LdapConfiguration, LdapConnectionInfo
 from ..xlate import XLATOR, format_list
 
-__version__ = '0.11.9'
+__version__ = '0.12.0'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -435,6 +435,15 @@ class BaseLdapApplication(BaseDPXApplication):
 
             ldap_group.add_argument('-I', '--instance', **arg_params)
 
+            if not self.use_multiple_ldap_connections:
+
+                ldap_group.add_argument(
+                    '-b', '--base-dn', metavar='DN', dest='ldap_base_dn',
+                    help=_(
+                        'Override the configured base DN of the instance used as the '
+                        'root for the LDAP searches.')
+                )
+
         if self.show_cmdline_ldap_timeout:
             ldap_group.add_argument(
                 '-T', '--timeout', metavar=_('SECONDS'), dest='ldap_timeout',
@@ -589,6 +598,9 @@ class BaseLdapApplication(BaseDPXApplication):
 
         self._validate_given_instances(filtered_instances)
 
+        if not self.use_multiple_ldap_connections:
+            self._apply_target_cmdline_params(filtered_instances)
+
         if self.verbose > 1:
             LOG.debug(_('LDAP instances to use:') + ' ' + pp(self.ldap_instances))
 
@@ -614,6 +626,15 @@ class BaseLdapApplication(BaseDPXApplication):
         if not all_ok:
             self.exit(1)
 
+    # -------------------------------------------------------------------------
+    def _apply_target_cmdline_params(self, filtered_instances):
+
+        for inst in filtered_instances:
+
+            v = getattr(self.args, 'ldap_base_dn', None)
+            if v:
+                self.cfg.ldap_connection[inst].base_dn = v
+
     # -------------------------------------------------------------------------
     def _init_default_connection(self):