Unverified Commit 9e696e87 authored by Peter Stanko's avatar Peter Stanko
Browse files

Better Logging for LDAP search and ldap integration

parent d0ce30c1
Pipeline #13211 failed with stage
in 31 minutes and 55 seconds
......@@ -38,6 +38,7 @@ class UserLdapService:
Returns(int): User's uco
"""
username = self.user.username
log.info(f"[LDAP] Extracting uco for: {self.user.log_name}")
user_entity = self.ldap.search(f"uid={username},ou=People")
log.debug(f"[LDAP] User ({username}): {user_entity}")
if not user_entity:
......@@ -88,6 +89,7 @@ class UserService:
def __update_uco_using_ldap(self, data):
if self.ldap.is_enabled:
log.debug("[LDAP] Ldap is enabled, extracting UCO")
uco = self.ldap.extract_uco()
if uco:
data['uco'] = uco
......
......@@ -54,6 +54,7 @@ class LDAPWrapper(object):
"""
if not self._ldap_server and self.is_enabled:
self._ldap_server = ldap3.Server(self.ldap_url, get_info=ldap3.ALL)
log.info(f"[LDAP] Creating LDAP server instance {self.ldap_url}: {self._ldap_server}")
return self._ldap_server
@property
......@@ -61,11 +62,18 @@ class LDAPWrapper(object):
connection = None
if self.ldap is not None:
connection = ldap3.Connection(self.ldap, auto_bind=True)
log.debug(f"[LDAP] Creating LDAP connection instance: {connection}}")
return connection
def search(self, selector: str):
selector = selector + self.selector_base
log.debug(f"[LDAP] Search {self.ldap_url}: ({selector})")
self.ldap_connection.search(selector, '(objectclass=*)', attributes=ldap3.ALL_ATTRIBUTES)
result = self.ldap_connection.entries[0]
log.debug(f"[LDAP] Search ({selector}): {result}")
return result
entries = self.ldap_connection.entries
if entries:
result = entries[0]
log.debug(f"[LDAP] Search ({selector}): {result}")
return result
else:
log.warning(f"[LDAP] Not found any entry for selector: {selector}")
return None
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment