phi/src/phi/ldap/user.py

27 lines
612 B
Python
Raw Normal View History

2017-12-21 13:44:54 +01:00
from phi.ldap.entry import get_entry_by_uid
from phi.ldap.utils import flatten_attributes
def user_attributes_mapping(client):
return {
2020-08-29 20:12:02 +02:00
client.attribute_id: "uid",
client.attribute_mail: "mail",
"createTimestamp": "created_at",
"modifyTimestamp": "modified_at",
2017-12-21 13:44:54 +01:00
}
def get_user_by_uid(client, uid):
entry = get_entry_by_uid(client, uid)
if not entry:
return None
mapping = user_attributes_mapping(client)
2020-08-29 20:12:02 +02:00
user = {
mapping[k]: v for k, v in entry["attributes"].items() if k in mapping.keys()
}
2017-12-21 13:44:54 +01:00
return flatten_attributes(user)