27 lines
612 B
Python
27 lines
612 B
Python
from phi.ldap.entry import get_entry_by_uid
|
|
from phi.ldap.utils import flatten_attributes
|
|
|
|
|
|
def user_attributes_mapping(client):
|
|
return {
|
|
client.attribute_id: "uid",
|
|
client.attribute_mail: "mail",
|
|
"createTimestamp": "created_at",
|
|
"modifyTimestamp": "modified_at",
|
|
}
|
|
|
|
|
|
def get_user_by_uid(client, uid):
|
|
entry = get_entry_by_uid(client, uid)
|
|
|
|
if not entry:
|
|
return None
|
|
|
|
mapping = user_attributes_mapping(client)
|
|
|
|
user = {
|
|
mapping[k]: v for k, v in entry["attributes"].items() if k in mapping.keys()
|
|
}
|
|
|
|
return flatten_attributes(user)
|