phi/src/phi/ldap/user.py

23 lines
508 B
Python
Raw Normal View History

2017-12-21 13:44:54 +01:00
from phi.ldap.entry import get_entry_by_uid
def get_user_by_uid(client, uid):
2020-09-30 16:38:31 +02:00
shown_keys = ['uid', 'mail', 'createTimestamp', 'modifyTimestamp']
2017-12-21 13:44:54 +01:00
entry = get_entry_by_uid(client, uid)
if not entry:
return None
2020-09-30 16:38:31 +02:00
def flatten(attr):
if isinstance(attr, list) and len(attr)==1:
return attr[0]
else:
return attr
2017-12-21 13:44:54 +01:00
2020-09-30 16:38:31 +02:00
user = {k: flatten(attr)
for k, attr in entry['attributes'].items()
if k in shown_keys}
2017-12-21 13:44:54 +01:00
2020-09-30 16:38:31 +02:00
return user