From: Frank Brehm Date: Mon, 31 Oct 2022 16:55:22 +0000 (+0100) Subject: Generating of LDAP entries to create X-Git-Tag: 0.7.0^2~1^2~15 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=d25466ffd195ddf76b78ff31ebf86be274b3de65;p=pixelpark%2Fpp-admin-tools.git Generating of LDAP entries to create --- diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 9ca0932..868ff23 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -1499,6 +1499,34 @@ class BaseLdapApplication(BaseDPXApplication): return attr_changes + # ------------------------------------------------------------------------- + def generate_create_entry(self, src_attribs): + + object_classes = [] + target_entry = {} + + for attrib_name in src_attribs: + + if attrib_name.lower() == 'memberof': + if self.verbose > 2: + msg = _("Attribute {!r} will not be touched.").format(attrib_name) + LOG.debug(msg) + continue + + if attrib_name.lower() == 'objectclass': + for object_class in sorted(src_attribs[attrib_name], key=str.lower): + object_classes.append(object_class) + continue + + if not src_attribs[attrib_name]: + continue + + target_entry[attrib_name] = [] + for value in src_attribs[attrib_name]: + target_entry[attrib_name].append(value) + + return (object_classes, target_entry) + # ============================================================================= if __name__ == "__main__": diff --git a/lib/pp_admintools/app/mirror_ldap.py b/lib/pp_admintools/app/mirror_ldap.py index fb2b58f..0ebcc68 100644 --- a/lib/pp_admintools/app/mirror_ldap.py +++ b/lib/pp_admintools/app/mirror_ldap.py @@ -24,6 +24,7 @@ from ldap3 import ALL_ATTRIBUTES # from fb_tools.common import to_bool, is_sequence # from fb_tools.collections import FrozenCIStringSet, CIStringSet, CIDict from fb_tools.collections import CIDict, CIStringSet +from fb_tools.xlate import format_list from .. import pp @@ -298,6 +299,27 @@ class MirrorLdapApplication(BaseLdapApplication): continue self.src_struct_dns.add(dn) + no_total = len(self.src_dns) + no_struct = len(self.src_struct_dns) + no_non_struct = no_total - no_struct + + msgs = [] + + msgs.append(ngettext( + "Found total one entry in source LDAP", "Found {no} entries in source LDAP", + no_total).format(no=no_total)) + + msgs.append(ngettext( + "one structural entry in source LDAP", "{no} structural entries in source LDAP", + no_struct).format(no=no_struct)) + + msgs.append(ngettext( + "one non-structural entry in source LDAP.", + "{no} non-structural entries in source LDAP.", + no_non_struct).format(no=no_non_struct)) + + LOG.info(format_list(msgs)) + if self.verbose > 2: msg = _("Found structural DNs in instance {!r}:").format(self.src_instance) LOG.debug(msg + '\n' + pp(self.src_struct_dns.as_list())) @@ -332,6 +354,27 @@ class MirrorLdapApplication(BaseLdapApplication): continue self.tgt_struct_dns_current.add(dn) + no_total = len(self.tgt_dns_current) + no_struct = len(self.tgt_struct_dns_current) + no_non_struct = no_total - no_struct + + msgs = [] + + msgs.append(ngettext( + "Found total one entry in target LDAP", "Found {no} entries in target LDAP", + no_total).format(no=no_total)) + + msgs.append(ngettext( + "one structural entry in target LDAP", "{no} structural entries in target LDAP", + no_struct).format(no=no_struct)) + + msgs.append(ngettext( + "one non-structural entry in target LDAP.", + "{no} non-structural entries in target LDAP.", + no_non_struct).format(no=no_non_struct)) + + LOG.info(format_list(msgs)) + if self.verbose > 2: msg = _("Found structural DNs in instance {!r}:").format(self.tgt_instance) LOG.debug(msg + '\n' + pp(self.tgt_struct_dns_current.as_list())) @@ -548,6 +591,13 @@ class MirrorLdapApplication(BaseLdapApplication): else: LOG.debug(_("Target entry {!r} not found.").format(dn)) + (object_classes, target_entry) = self.generate_create_entry(src_attribs) + msg = _("Got create data for DN {!r}:").format(dn) + msg += '\nobjectClasses:\n' + pp(object_classes) + msg += "\nAttributes:\n" + pp(target_entry) + LOG.debug(msg) + self.mirrored_entries += 1 + count += 1 if self.limit and self.mirrored_entries >= self.limit: break