phi/src/phi/api/rest.py

25 lines
615 B
Python
Raw Normal View History

2017-12-21 13:44:54 +01:00
from aiohttp.web import json_response, View
from aiohttp.web import HTTPNotFound, HTTPUnprocessableEntity
2017-12-16 23:03:03 +01:00
2017-12-21 13:44:54 +01:00
from phi.logging import get_logger
from phi.ldap.user import get_user_by_uid
from phi.api.utils import serialize
2017-12-16 23:03:03 +01:00
2017-12-21 13:44:54 +01:00
log = get_logger(__name__)
2017-12-21 13:44:54 +01:00
class User(View):
async def get(self):
2020-11-20 12:04:17 +01:00
uid = self.request.match_info.get("uid", None)
2017-12-27 11:02:38 +01:00
2017-12-21 13:44:54 +01:00
if uid is None:
return HTTPUnprocessableEntity()
2020-11-20 12:04:17 +01:00
client = self.request.app["ldap_client"]
2017-12-21 13:44:54 +01:00
user = get_user_by_uid(client, uid)
if not user:
return HTTPNotFound()
return json_response(serialize(user))