diff --git a/mylib/ldap.py b/mylib/ldap.py index 4ee1757..056b5df 100644 --- a/mylib/ldap.py +++ b/mylib/ldap.py @@ -228,6 +228,7 @@ class LdapServer: def format_changes(old, new, ignore_attrs=None, prefix=None): """ Format changes (modlist) on an object based on its old and new attributes values to display/log it """ msg = [] + prefix = prefix if prefix else '' for (op, attr, val) in modlist.modifyModlist(old, new, ignore_attr_types=ignore_attrs if ignore_attrs else []): if op == ldap.MOD_ADD: # pylint: disable=no-member op = 'ADD' @@ -238,7 +239,7 @@ class LdapServer: else: op = 'UNKNOWN (=%s)' % op if val is None and op == 'DELETE': - msg.append('%s - %s %s' % (prefix if prefix else '', op, attr)) + msg.append('%s - %s %s' % (prefix, op, attr)) else: msg.append('%s - %s %s: %s' % (prefix, op, attr, val)) return '\n'.join(msg) @@ -502,6 +503,12 @@ class LdapClient: return None return (old, new) + def format_changes(self, changes, protected_attrs=None, prefix=None): + return self.cnx.format_changes( + changes[0], changes[1], + ignore_attrs=protected_attrs, prefix=prefix + ) + def add_object(self, dn, attrs): """ Add an object