phi/src/phi/ldap/user.py

23 lines
508 B
Python

from phi.ldap.entry import get_entry_by_uid
def get_user_by_uid(client, uid):
shown_keys = ['uid', 'mail', 'createTimestamp', 'modifyTimestamp']
entry = get_entry_by_uid(client, uid)
if not entry:
return None
def flatten(attr):
if isinstance(attr, list) and len(attr)==1:
return attr[0]
else:
return attr
user = {k: flatten(attr)
for k, attr in entry['attributes'].items()
if k in shown_keys}
return user