]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Start writing aliases
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 16:17:33 +0000 (18:17 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 16:17:33 +0000 (18:17 +0200)
lib/pp_admintools/app/barracuda_sync.py

index 2ced50fb3eb1ce053e7d51981a1468a2cceb0fdb..e84e497ae94287213c4201d767704cea968cc560 100644 (file)
@@ -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()
 
 
 # =============================================================================