Skip to content
Snippets Groups Projects
Commit f0384baf authored by schulmax's avatar schulmax
Browse files

[TASK] Improves ldap loader update logging

parent c6faa401
Branches
No related tags found
No related merge requests found
...@@ -382,10 +382,10 @@ class LdapLoader(AbstractLoader): ...@@ -382,10 +382,10 @@ class LdapLoader(AbstractLoader):
attributes = modlist.modifyModlist(old_entity_dict, entity_dict) attributes = modlist.modifyModlist(old_entity_dict, entity_dict)
try: try:
if self.dry: if self.dry:
logging.info('Would modify dn {} with {} '.format(dn, str(attributes))) logging.info('Would modify dn {} with {} '.format(dn, self._generate_modify_logging(attributes, old_entity_dict, entity_dict)))
else: else:
connection.modify_s(dn, attributes) connection.modify_s(dn, attributes)
logging.info('Modified dn {} with {} '.format(dn, str(attributes))) logging.info('Modified dn {} with {} '.format(dn, self._generate_modify_logging(attributes, old_entity_dict, entity_dict)))
except Exception, e: except Exception, e:
logging.warn('Update failed for dn \'' + dn + '\': ' + str(e)) logging.warn('Update failed for dn \'' + dn + '\': ' + str(e))
...@@ -438,3 +438,14 @@ class LdapLoader(AbstractLoader): ...@@ -438,3 +438,14 @@ class LdapLoader(AbstractLoader):
elif element == None: elif element == None:
data[key] = '' data[key] = ''
return data return data
def _generate_modify_logging(self, attributes, old, new):
'''Generates a nicer representation of the executed query than str(attributes) would'''
changed_attributes = []
output = ''
for operation in attributes:
if operation[1] not in changed_attributes:
changed_attributes.append(operation[1])
for attribute in changed_attributes:
output += attribute + ': ' + old[attribute] + ' -> ' + new[attribute] + ', '
return output[:-2]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment