]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Renaming some attributes of LDAP config and app
authorFrank Brehm <frank@brehm-online.com>
Wed, 18 May 2022 10:13:07 +0000 (12:13 +0200)
committerFrank Brehm <frank@brehm-online.com>
Wed, 18 May 2022 10:13:07 +0000 (12:13 +0200)
lib/pp_admintools/ldap_app.py
lib/pp_admintools/ldap_config.py

index a84bf6fde4fde48df9ee822b6685288cb8a21849..34a2746c7caa2964ec826cef5507dd0f482167f6 100644 (file)
@@ -40,7 +40,7 @@ from .argparse_actions import PortOptionAction
 from .ldap_config import LdapConfigError, LdapConnectionInfo, LdapConfiguration
 from .ldap_config import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS, DEFAULT_TIMEOUT, MAX_TIMEOUT
 
-__version__ = '0.1.0'
+__version__ = '0.1.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -149,15 +149,17 @@ class BaseLdapApplication(FbConfigApplication):
     Base class for all application classes using LDAP.
     """
 
+    use_default_ldap_connection = True
+    show_cmdline_ldap_timeout = True
+
     # -------------------------------------------------------------------------
     def __init__(
         self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None,
             cfg_class=LdapConfiguration, initialized=False, usage=None, description=None,
             argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None,
-            use_default_ldap_connection=True, config_dir=DEFAULT_CONFIG_DIR):
+            config_dir=DEFAULT_CONFIG_DIR):
 
         self._password_file = None
-        self._use_default_ldap_connection = bool(use_default_ldap_connection)
 
         super(BaseLdapApplication, self).__init__(
             appname=appname, verbose=verbose, version=version, base_dir=base_dir,
@@ -166,12 +168,6 @@ class BaseLdapApplication(FbConfigApplication):
             env_prefix=env_prefix, config_dir=config_dir
         )
 
-    # -----------------------------------------------------------
-    @property
-    def use_default_ldap_connection(self):
-        """Should there be command line parameters for the default LDAP connection."""
-        return self._use_default_ldap_connection
-
     # -----------------------------------------------------------
     @property
     def password_file(self):
@@ -215,6 +211,7 @@ class BaseLdapApplication(FbConfigApplication):
         res = super(BaseLdapApplication, self).as_dict(short=short)
 
         res['password_file'] = self.password_file
+        res['show_cmdline_ldap_timeout'] = self.show_cmdline_ldap_timeout
         res['use_default_ldap_connection'] = self.use_default_ldap_connection
 
         return res
@@ -295,13 +292,14 @@ class BaseLdapApplication(FbConfigApplication):
                 help=_("Use contents of PASSWORD_FILE as the password for simple authentication."),
             )
 
-        self.arg_parser.add_argument(
-            '-T', '--timeout', metavar=_('SECONDS'), dest="ldap_timeout",
-            action=TimeoutOptionAction,
-            help=_(
-                "Using the given timeout in seconds for all LDAP operations. "
-                "Default: {}").format(DEFAULT_TIMEOUT),
-        )
+        if self.show_cmdline_ldap_timeout:
+            self.arg_parser.add_argument(
+                '-T', '--timeout', metavar=_('SECONDS'), dest="ldap_timeout",
+                action=TimeoutOptionAction,
+                help=_(
+                    "Using the given timeout in seconds for all LDAP operations. "
+                    "Default: {}").format(DEFAULT_TIMEOUT),
+            )
 
     # -------------------------------------------------------------------------
     def post_init(self):
@@ -323,8 +321,8 @@ class BaseLdapApplication(FbConfigApplication):
         if not self.use_default_ldap_connection:
             return
 
-        if 'default' in self.cfg.connection:
-            default_connection = self.cfg.connection['default']
+        if 'default' in self.cfg.ldap_connection:
+            default_connection = self.cfg.ldap_connection['default']
         else:
             default_connection = LdapConnectionInfo(
                 appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
@@ -334,7 +332,7 @@ class BaseLdapApplication(FbConfigApplication):
                 base_dn=LdapConfiguration.default_base_dn,
                 bind_dn=LdapConfiguration.default_bind_dn,
                 initialized=False)
-            self.cfg.connection['default'] = default_connection
+            self.cfg.ldap_connection['default'] = default_connection
 
         v = getattr(self.args, 'ldap_host', None)
         if v:
@@ -361,7 +359,7 @@ class BaseLdapApplication(FbConfigApplication):
 
         v = getattr(self.args, 'ldap_timeout', None)
         if v:
-            self.cfg.timeout = v
+            self.cfg.ldap_timeout = v
 
 
 # =============================================================================
index ca2c3c611625c423300e2215eb4a7e4e861edd5c..79b8df9fefff0b5c5cceb1cee001be3911244ebd 100644 (file)
@@ -30,7 +30,7 @@ from . import MAX_PORT_NUMBER, DEFAULT_CONFIG_DIR
 
 from .xlate import XLATOR
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -316,7 +316,7 @@ class LdapConfiguration(BaseMultiConfig):
         if 'ldap' not in add_stems:
             add_stems.append('ldap')
 
-        self.timeout = DEFAULT_TIMEOUT
+        self.ldap_timeout = DEFAULT_TIMEOUT
 
         super(LdapConfiguration, self).__init__(
             appname=appname, verbose=verbose, version=version, base_dir=base_dir,
@@ -326,7 +326,7 @@ class LdapConfiguration(BaseMultiConfig):
             ensure_privacy=ensure_privacy, initialized=False,
         )
 
-        self.connection = LdapConnectionDict()
+        self.ldap_connection = LdapConnectionDict()
 
         default_connection = LdapConnectionInfo(
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
@@ -334,7 +334,7 @@ class LdapConfiguration(BaseMultiConfig):
             port=self.default_ldap_port, base_dn=self.default_base_dn,
             bind_dn=self.default_bind_dn, initialized=False)
 
-        self.connection['default'] = default_connection
+        self.ldap_connection['default'] = default_connection
 
     # -------------------------------------------------------------------------
     def eval_section(self, section_name):
@@ -348,7 +348,7 @@ class LdapConfiguration(BaseMultiConfig):
             for key in section.keys():
                 sub = section[key]
                 if key.lower.strip() == 'timeout':
-                    self._eval_timeout(sub)
+                    self._eval_ldap_timeout(sub)
                     continue
                 self._eval_ldap_connection(key, sub)
             return
@@ -359,7 +359,7 @@ class LdapConfiguration(BaseMultiConfig):
             self._eval_ldap_connection(connection_name, section)
 
     # -------------------------------------------------------------------------
-    def _eval_timeout(self, value):
+    def _eval_ldap_timeout(self, value):
 
         timeout = DEFAULT_TIMEOUT
 
@@ -376,7 +376,7 @@ class LdapConfiguration(BaseMultiConfig):
             LOG.error(msg)
             continue
 
-        self.timeout = timeout
+        self.ldap_timeout = timeout
 
     # -------------------------------------------------------------------------
     def _eval_ldap_connection(self, connection_name, section):
@@ -439,7 +439,7 @@ class LdapConfiguration(BaseMultiConfig):
             msg = _("Unknown LDAP configuration key found in section {!r}.").format(section_name)
             LOG.error(msg)
 
-        self.connection[connection_name] = connection
+        self.ldap_connection[connection_name] = connection
 
 
 # =============================================================================