Skip to content

Commit

Permalink
reverted routes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilian committed Dec 13, 2024
1 parent bec71a9 commit d44e995
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 54 deletions.
20 changes: 5 additions & 15 deletions jhub_apps/service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ async def create_server(
user_options=server.user_options,
)


@router.post("/server/")
@router.post("/server/{server_name}")
async def start_server(
Expand All @@ -175,25 +176,15 @@ async def start_server(
# User could be starting a shared server, in which case the
# user starting the server will not be the owner of the server
server_owner = request.query_params.get("owner", user.name)

# Check if the server is shared and the user has access
shared_servers = get_shared_servers(current_hub_user=hub_client.get_user())
if server_name not in [s['name'] for s in shared_servers] and server_owner != user.name:
logger.error(f"User '{user.name}' does not have access to shared server '{server_name}'")
raise HTTPException(
detail=f"User '{user.name}' doesn't have access to shared server: '{server_name}'",
status_code=status.HTTP_403_FORBIDDEN,
)

# Attempt to start the server
try:
response = hub_client.start_server(
username=server_owner,
servername=server_name,
)
if response.status_code in [403, 404]:
raise HTTPException(
detail=f"Failed to start server: {response.text}",
detail=f"User doesn't have permissions to start server: '{server_name}' "
f"or the server with this name does not exist",
status_code=status.HTTP_403_FORBIDDEN,
)
response.raise_for_status()
Expand All @@ -202,15 +193,14 @@ async def start_server(
detail=f"Probably server '{server_name}' is already running: {e}",
status_code=status.HTTP_400_BAD_REQUEST,
)

if response is None:
raise HTTPException(
detail=f"Server '{server_name}' not found",
detail=f"server '{server_name}' not found",
status_code=status.HTTP_404_NOT_FOUND,
)

return response.status_code


@router.put("/server/{server_name}")
async def update_server(
server: ServerCreation = Depends(Checker(ServerCreation)),
Expand Down
Loading

0 comments on commit d44e995

Please sign in to comment.