LdapServer: add get_changes() and format_changes() methods

This commit is contained in:
Benjamin Renard 2020-09-23 15:55:53 +02:00 committed by root
parent d49ae5aabb
commit d336ab3a8d

View file

@ -106,6 +106,26 @@ class LdapServer(object):
return False return False
return True return True
def get_changes(self, old, new, ignore_attrs=[]):
return modlist.modifyModlist(old, new, ignore_attr_types=ignore_attrs)
def format_changes(self, old, new, ignore_attrs=[], prefix=''):
msg = []
for (op, attr, val) in modlist.modifyModlist(old, new, ignore_attr_types=ignore_attrs):
if op == ldap.MOD_ADD:
op = 'ADD'
elif op == ldap.MOD_DELETE:
op = 'DELETE'
elif op == ldap.MOD_REPLACE:
op = 'REPLACE'
else:
op = 'UNKNOWN (=%s)' % op
if val is None and op == 'DELETE':
msg.append('%s - %s %s' % (prefix, op, attr))
else:
msg.append('%s - %s %s: %s' % (prefix, op, attr, val))
return '\n'.join(msg)
def rename_object(self,dn,new_rdn): def rename_object(self,dn,new_rdn):
try: try:
self.logger.debug("LdapServer - Rename %s in %s" % (dn,new_rdn)) self.logger.debug("LdapServer - Rename %s in %s" % (dn,new_rdn))