From: Frank Brehm Date: Wed, 17 May 2023 09:35:06 +0000 (+0200) Subject: Adding possibility to use another default LDAP instance X-Git-Tag: 0.9.0~1^2~50 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=9867330077a385eb3c6c053053bea4bcbdf510be;p=pixelpark%2Fpp-admin-tools.git Adding possibility to use another default LDAP instance --- diff --git a/etc/ldap.yaml.default b/etc/ldap.yaml.default index f7f55a6..fc73cbc 100644 --- a/etc/ldap.yaml.default +++ b/etc/ldap.yaml.default @@ -22,6 +22,16 @@ ldap: readonly: false sync-source: 'dpx-prod' tier: 'dev' + dpx-dev-mail: + host: 'dev-ldap2.pixelpark.com' + ldaps: true + port: 636 + base_dn: 'o=isp' + bind_dn: 'uid=mail-service,ou=Services,o=Pixelpark,o=isp' + # bind_pw: ****** + is_admin: false + readonly: false + tier: 'dev' dpx-dev-ro: host: 'dev-ldap2.pixelpark.com' ldaps: true @@ -42,6 +52,16 @@ ldap: is_admin: true readonly: false tier: 'prod' + dpx-prod-mail: + host: 'prd-ds.pixelpark.com' + ldaps: true + port: 636 + base_dn: 'o=isp' + bind_dn: 'uid=mail-service,ou=Services,o=Pixelpark,o=isp' + # bind_pw: ****** + is_admin: false + readonly: false + tier: 'prod' dpx-prod-ro: host: 'prd-ds.pixelpark.com' ldaps: true diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index e56998d..e41a975 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -25,7 +25,7 @@ from fb_tools.xlate import format_list from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.6.1' +__version__ = '0.6.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -83,7 +83,8 @@ class BarracudaSyncApp(BaseLdapApplication): use_default_ldap_connection = False use_multiple_ldap_connections = False show_cmdline_ldap_timeout = True - apply_default_ldap_instance_if_not_given = False + apply_default_ldap_instance_if_not_given = True + default_default_ldap_instance = 'dpx-prod-mail' # ------------------------------------------------------------------------- def __init__(self, appname=None, base_dir=None): diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index d42234d..1898190 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -54,7 +54,7 @@ from ..config.ldap import LdapConnectionInfo, LdapConfiguration # rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from ..config.ldap import DEFAULT_TIMEOUT -__version__ = '0.11.3' +__version__ = '0.11.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -171,6 +171,7 @@ class BaseLdapApplication(BaseDPXApplication): use_multiple_ldap_connections = False show_cmdline_ldap_timeout = True apply_default_ldap_instance_if_not_given = True + default_default_ldap_instance = 'default' # pattern_re_ldap_dn = ( # '^([a-z][a-z0-9-]*)=(?![ #])(((?![\\="+,;<>]).)|(\\[ \\#="+,;<>])|(\\[a-f0-9][a-f0-9]))*' @@ -403,7 +404,7 @@ class BaseLdapApplication(BaseDPXApplication): } help_default_inst = _( - "If not given, then the instance {!r} will be used.").format('default') + "If not given, then the instance {!r} will be used.").format(self.default_default_ldap_instance) help_single = _( "The LDAP instance (LDAP cluster) from configuration, " @@ -468,7 +469,7 @@ class BaseLdapApplication(BaseDPXApplication): self._init_default_connection() if self.use_default_ldap_connection: - self.ldap_instances = ['default'] + self.ldap_instances = [self.default_default_ldap_instance] return LOG.debug(_("Checking given instances.")) @@ -493,7 +494,7 @@ class BaseLdapApplication(BaseDPXApplication): if inst_cleared != '': self.ldap_instances.append(inst.lower()) else: - self.ldap_instances = ['default'] + self.ldap_instances = [self.default_default_ldap_instance] self._verify_instances() @@ -502,11 +503,11 @@ class BaseLdapApplication(BaseDPXApplication): instances = [] for inst in self.cfg.ldap_connection.keys(): - if inst != 'default': + if inst != self.default_default_ldap_instance: instances.append(inst) instances.sort(key=str.lower) - if 'default' in self.cfg.ldap_connection: - instances.insert(0, 'default') + if self.default_default_ldap_instance in self.cfg.ldap_connection: + instances.insert(0, self.default_default_ldap_instance) max_key_len = 1 max_tier_len = 1 @@ -593,9 +594,9 @@ class BaseLdapApplication(BaseDPXApplication): self.ldap_instances = filtered_instances return - if 'default' in self.cfg.ldap_connection: + if self.default_default_ldap_instance in self.cfg.ldap_connection: if self.apply_default_ldap_instance_if_not_given: - filtered_instances.insert(0, 'default') + filtered_instances.insert(0, self.default_default_ldap_instance) all_ok = True for given_inst in self.ldap_instances: @@ -611,8 +612,8 @@ class BaseLdapApplication(BaseDPXApplication): # ------------------------------------------------------------------------- def _init_default_connection(self): - if 'default' in self.cfg.ldap_connection: - default_connection = self.cfg.ldap_connection['default'] + if self.default_default_ldap_instance in self.cfg.ldap_connection: + default_connection = self.cfg.ldap_connection[self.default_default_ldap_instance] else: default_connection = LdapConnectionInfo( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, @@ -622,7 +623,7 @@ class BaseLdapApplication(BaseDPXApplication): base_dn=LdapConfiguration.default_base_dn, bind_dn=LdapConfiguration.default_bind_dn, initialized=False) - self.cfg.ldap_connection['default'] = default_connection + self.cfg.ldap_connection[self.default_default_ldap_instance] = default_connection v = getattr(self.args, 'ldap_host', None) if v: