From c41c5ac8be2ee9b12aedea0c16115efd80cf506c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 26 May 2023 11:43:58 +0200 Subject: [PATCH] Adding modifying of existing aliases. --- lib/pp_admintools/app/barracuda_sync.py | 62 +++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index 294cc62..5a4f54e 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -31,7 +31,7 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.9.4' +__version__ = '0.9.5' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -843,7 +843,9 @@ class BarracudaSyncApp(BaseLdapApplication): LOG.info(_('Removing all no more used alias entries ...')) inst = self.ldap_instances[0] - if not len(self.aliases_to_remove): + nr_aliases = len(self.aliases_to_remove) + + if not nr_aliases: msg = _('No aliases found to remove in LDAP.') LOG.info(msg) if self.wait_interval: @@ -855,6 +857,14 @@ class BarracudaSyncApp(BaseLdapApplication): if self.wait_interval: time.sleep(self.wait_interval) + self.empty_line() + msg = ngettext( + 'One alias entry removed in LDAP.', '{} alias entries removed in LDAP.', + nr_aliases).format(nr_aliases) + LOG.info(msg) + if self.wait_interval: + time.sleep(self.wait_interval * 10) + # ------------------------------------------------------------------------- def add_failing_ldap_entries(self): """Create failing LDAP entries.""" @@ -862,7 +872,9 @@ class BarracudaSyncApp(BaseLdapApplication): LOG.info(_('Adding failing LDAP aliases ...')) inst = self.ldap_instances[0] - if not len(self.aliases_to_create): + nr_aliases = len(self.aliases_to_create) + + if not nr_aliases: msg = _('No aliases found to create in LDAP.') LOG.info(msg) if self.wait_interval: @@ -877,6 +889,45 @@ class BarracudaSyncApp(BaseLdapApplication): if self.wait_interval: time.sleep(self.wait_interval) + self.empty_line() + msg = ngettext( + 'One alias entry created in LDAP.', '{} alias entries created in LDAP.', + nr_aliases).format(nr_aliases) + LOG.info(msg) + if self.wait_interval: + time.sleep(self.wait_interval * 10) + + # ------------------------------------------------------------------------- + def modify_existing_entries(self): + """Modify existing LDAP entries below the Barracuda container.""" + self.empty_line() + LOG.info(_('Modifying existing alieas entries ...')) + inst = self.ldap_instances[0] + + nr_aliases = len(self.aliases_to_modify.keys()) + + if not nr_aliases: + msg = _('No aliases found to mofify in LDAP.') + LOG.info(msg) + if self.wait_interval: + time.sleep(self.wait_interval * 10) + return + + for dn in sorted(self.aliases_to_modify.keys(), key=cmp_to_key(self.compare_ldap_dns)): + modify_data = self.aliases_to_modify[dn] + LOG.info(_('Modifying LDAP alias {!r} ...').format(dn)) + self.modify_entry(inst, dn, modify_data) + if self.wait_interval: + time.sleep(self.wait_interval) + + self.empty_line() + msg = ngettext( + 'One alias entry modified in LDAP.', '{} alias entries modified in LDAP.', + nr_aliases).format(nr_aliases) + LOG.info(msg) + if self.wait_interval: + time.sleep(self.wait_interval * 10) + # ------------------------------------------------------------------------- def _run(self): @@ -887,6 +938,11 @@ class BarracudaSyncApp(BaseLdapApplication): self.eval_diffs() self.remove_old_alias_entries() self.add_failing_ldap_entries() + self.modify_existing_entries() + + self.empty_line() + LOG.info(_('Finished.')) + self.empty_line() # ============================================================================= -- 2.39.5