docstrings: Added HTTP status

This commit is contained in:
Jörn-Michael Miehe 2022-04-01 17:05:57 +00:00
parent 762af5dd48
commit 5b68f5ef7e
2 changed files with 25 additions and 12 deletions

View file

@ -58,6 +58,10 @@ async def get_current_config(
) -> Config: ) -> Config:
""" """
Get the current configuration if it exists. Get the current configuration if it exists.
Status:
- 400: `kiwi-vpn` not installed
""" """
# fail if not configured # fail if not configured
@ -73,6 +77,10 @@ async def get_current_user(
) -> User: ) -> User:
""" """
Get the currently logged-in user if it exists. Get the currently logged-in user if it exists.
Status:
- 403: invalid auth token, or user not found
""" """
# don't use error 404 here - possible user enumeration # don't use error 404 here - possible user enumeration
@ -89,23 +97,32 @@ async def get_current_user(
async def get_user_by_name( async def get_user_by_name(
user_name: str, user_name: str,
_: Config = Depends(get_current_config), ) -> User:
) -> User | None:
""" """
Get a user by name. Get a user by name.
Status:
- 404: user not found
""" """
return User.get(user_name) # fail if device doesn't exist
if (user := User.get(user_name)) is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
return user
async def get_device_by_id( async def get_device_by_id(
device_id: int, device_id: int,
current_config: Config = Depends(get_current_config), ) -> Device:
) -> Device | None: """
Get a device by ID.
# can't connect to an unconfigured database Status:
if current_config is None:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST) - 404: device not found
"""
# fail if device doesn't exist # fail if device doesn't exist
if (device := Device.get(device_id)) is None: if (device := Device.get(device_id)) is None:

View file

@ -37,10 +37,6 @@ async def add_device(
if not current_user.can_create(Device, owner): if not current_user.can_create(Device, owner):
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
# fail if owner doesn't exist
if owner is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
# create the new device # create the new device
new_device = Device.create( new_device = Device.create(
owner=owner, owner=owner,