Skip to content

Commit

Permalink
Do not raise for index error
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Mar 2, 2024
1 parent c7af09a commit 6d34c0e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.minio.sys
*.DS_Store
*.app
logs/
Expand Down
2 changes: 1 addition & 1 deletion hypha/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ async def get_service(self, query: Union[dict, str], context=None):
# No need to patch the service config
# because the service is already patched
return service_api
raise IndexError(f"Service not found: {sid} in workspace {workspace}")
return None
service_info = random.choice(services)
rpc = await self.setup()
service_api = await rpc.get_remote_service(service_info["id"])
Expand Down
15 changes: 6 additions & 9 deletions hypha/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,28 @@ def __init__(self, store: RedisStore) -> None:
router = APIRouter()
router.route_class = GzipRoute
self.store = store

@router.get("/authorize")
async def auth_proxy(request: Request):
# Construct the full URL for the Auth0 authorize endpoint with the query parameters
auth0_authorize_url = f"https://{AUTH0_DOMAIN}/authorize?{request.query_params}"
auth0_authorize_url = (
f"https://{AUTH0_DOMAIN}/authorize?{request.query_params}"
)

# Redirect the client to the constructed URL
return RedirectResponse(url=auth0_authorize_url)


@router.post("/oauth/token")
async def token_proxy(request: Request):
form_data = await request.form()
async with httpx.AsyncClient() as client:
auth0_response = await client.post(
f"https://{AUTH0_DOMAIN}/oauth/token",
data=form_data,
headers={"Content-Type": "application/x-www-form-urlencoded"}
)

return JSONResponse(
status_code=200,
content=auth0_response.json()
headers={"Content-Type": "application/x-www-form-urlencoded"},
)

return JSONResponse(status_code=200, content=auth0_response.json())

@router.get("/authorize")
async def auth_proxy(request: Request):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_startup_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ async def test_launch_external_services(fastapi_server):
assert await external_service.test(1) == 100
await proc.kill()
await asyncio.sleep(0.1)
with pytest.raises(
Exception, match=r".*IndexError: Service not found: external-test-service.*"
):
await server.get_service("external-test-service")

svc = await server.get_service("external-test-service")
assert svc is None
proc = await launch_external_services(
server,
"python -m http.server 9391",
Expand Down

0 comments on commit 6d34c0e

Please sign in to comment.