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
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,
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):
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
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):
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,
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:
v = getattr(self.args, 'ldap_timeout', None)
if v:
- self.cfg.timeout = v
+ self.cfg.ldap_timeout = v
# =============================================================================
from .xlate import XLATOR
-__version__ = '0.2.0'
+__version__ = '0.2.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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,
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,
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):
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
self._eval_ldap_connection(connection_name, section)
# -------------------------------------------------------------------------
- def _eval_timeout(self, value):
+ def _eval_ldap_timeout(self, value):
timeout = DEFAULT_TIMEOUT
LOG.error(msg)
continue
- self.timeout = timeout
+ self.ldap_timeout = timeout
# -------------------------------------------------------------------------
def _eval_ldap_connection(self, connection_name, section):
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
# =============================================================================