-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): secure
/exports
when auth is enabled (#4589)
- Loading branch information
1 parent
0ce3fae
commit b7af851
Showing
5 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
from .auth import router as auth_router | ||
from .embeddings import create_embeddings_router | ||
from .v1 import create_v1_router | ||
|
||
__all__ = ["auth_router", "create_v1_router"] | ||
__all__ = [ | ||
"auth_router", | ||
"create_embeddings_router", | ||
"create_v1_router", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from fastapi import APIRouter, Depends | ||
from fastapi.responses import FileResponse | ||
from starlette.exceptions import HTTPException | ||
from starlette.requests import Request | ||
|
||
from phoenix.server.bearer_auth import is_authenticated | ||
|
||
|
||
def create_embeddings_router(authentication_enabled: bool) -> APIRouter: | ||
""" | ||
Instantiates a router for the embeddings API. | ||
""" | ||
router = APIRouter(dependencies=[Depends(is_authenticated)] if authentication_enabled else []) | ||
|
||
@router.get("/exports") | ||
async def download_exported_file(request: Request, filename: str) -> FileResponse: | ||
file = request.app.state.export_path / (filename + ".parquet") | ||
if not file.is_file(): | ||
raise HTTPException(status_code=404) | ||
return FileResponse( | ||
path=file, | ||
filename=file.name, | ||
media_type="application/x-octet-stream", | ||
) | ||
|
||
return router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters