From 7a003c8adebb06fdbb1a9041742e4ebc3a39fea6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 24 May 2023 18:17:33 +0200 Subject: [PATCH] Start writing aliases --- lib/pp_admintools/app/barracuda_sync.py | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index 2ced50f..e84e497 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -30,7 +30,7 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.8.8' +__version__ = '0.9.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -523,6 +523,7 @@ class BarracudaSyncApp(BaseLdapApplication): # ------------------------------------------------------------------------- def eval_diffs(self): """Evaluate all entries to create, to remove or to modify.""" + self.empty_line() LOG.info(_('Evaluating all LDAP entries to create, to remove or to modify.')) self.eval_entries_to_remove() @@ -791,6 +792,39 @@ class BarracudaSyncApp(BaseLdapApplication): return entry + # ------------------------------------------------------------------------- + def _create_ldap_entry_for_create(self, cn): + """Generate entry data to create e LDAP entry.""" + local_alias = self.existing_aliases[cn] + + oclasses = [] + oclasses.append('inetResource') + oclasses.append('mailRecipient') + oclasses.append('top') + + attributes = {} + + attributes['cn'] = [cn] + attributes['mail'] = [local_alias['alias']] + attributes['multiLineDescription'] = [] + for target in local_alias['targets']: + attributes['multiLineDescription'].append(target) + + return (oclasses, attributes) + + # ------------------------------------------------------------------------- + def add_failing_ldap_entries(self): + """Create failing LDAP entries.""" + self.empty_line() + LOG.info(_('Adding failing LDAP aliases ...')) + inst = self.ldap_instances[0] + + for cn in self.aliases_to_create: + dn = 'cn=' + cn + ',' + self.barracuda_base_dn + (oclasses, attributes) = self._create_ldap_entry_for_create(cn) + LOG.info(_('Creating LDAP alias {a!r} => {dn!r}.').format(a=cn, dn=dn)) + # self.add_entry(inst, dn, oclasses, attributes) + # ------------------------------------------------------------------------- def _run(self): @@ -799,6 +833,7 @@ class BarracudaSyncApp(BaseLdapApplication): self.read_barracuda_ldap_aliases() self.get_other_ldap_mail_entries() self.eval_diffs() + self.add_failing_ldap_entries() # ============================================================================= -- 2.39.5