Add LdapClient.format_changes() method

This commit is contained in:
Benjamin Renard 2021-07-12 13:37:41 +02:00
parent 21bd45ad25
commit 4ff38aa898

View file

@ -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