Skip to content
Snippets Groups Projects
Commit e4e8e563 authored by Jakob Berger's avatar Jakob Berger :key2: Committed by jakob
Browse files

Merge branch 'avinok2s/pygitlab-master'

parents e49ff17e ea1682d0
No related branches found
No related tags found
No related merge requests found
......@@ -7,28 +7,16 @@ class LdapHandler:
self.connection = ldap3.Connection(server, auto_bind=True)
self.default_context = default_context
def get_ldap_users(self, user_list: list, silent: bool = False, context: str = '__USEDEFAULT__'):
results = []
if context == '__USEDEFAULT':
def get_ldap_user(self, search_filter: dict, silent: bool = False, context: str = '__USEDEFAULT__',
attributes: list = ['sn', 'gn', 'objectclass']):
if context == '__USEDEFAULT__':
search_context = self.default_context
else:
search_context = context
i = 1
for user in user_list:
user = user.strip()
if not silent:
print("%s (%d/%d)" % (user, i, len(results)))
search_no = self.ldap.search(search_context, ldap3.SCOPE_SUBTREE, "uid=%s" % user, None)
search_res = self.ldap.result(search_no, 0)
if search_res[0] == 100:
dn = search_res[1][0][0]
name = search_res[1][0][1]['cn'][0]
mail = search_res[1][0][1]['mail'][0]
location = search_res[1][0][1]['l'][0]
results.append({'dn': dn, 'username': user, 'name': name, 'mail': mail, 'location': location})
return results
def connect(ldaphost: str, default_context: str = '', ssl: bool = False) -> LdapHandler:
return LdapHandler(ldaphost, default_context, ssl)
\ No newline at end of file
search_string = "(&"
for key, value in search_filter.items():
search_string += '(' + key + '=' + value + ')'
search_string += ')'
self.connection.search(search_context, search_string, attributes=attributes)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment