-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflows)!: add FastAPI router factory + WDL dir to WorkflowSet
- Loading branch information
1 parent
2c4e379
commit 3e98e61
Showing
2 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from fastapi import status | ||
from fastapi.exceptions import HTTPException | ||
from fastapi.responses import FileResponse | ||
from fastapi.routing import APIRouter | ||
|
||
from ..auth.middleware.fastapi import FastApiAuthMiddleware | ||
from .models import WorkflowDefinition | ||
from .workflow_set import WorkflowSet | ||
|
||
__all__ = [ | ||
"build_workflow_router", | ||
] | ||
|
||
|
||
def build_workflow_router(authz_middleware: FastApiAuthMiddleware, workflow_set: WorkflowSet) -> APIRouter: | ||
workflow_router = APIRouter(prefix="/workflows") | ||
|
||
@workflow_router.get("", dependencies=[authz_middleware.dep_public_endpoint()]) | ||
def workflow_list(): | ||
return workflow_set.workflow_dicts_by_type_and_id() | ||
|
||
@workflow_router.get("/", dependencies=[authz_middleware.dep_public_endpoint()]) | ||
def workflow_list_trailing_slash(): | ||
return workflow_set.workflow_dicts_by_type_and_id() | ||
|
||
# The endpoint with the .wdl suffix needs to come first, since we match in order and otherwise the whole thing, | ||
# including the suffix, would get passed as {workflow_id}. | ||
@workflow_router.get("/{workflow_id}.wdl", dependencies=[authz_middleware.dep_public_endpoint()]) | ||
def workflow_file(workflow_id: str): | ||
if (wdl := workflow_set.get_workflow_wdl_path(workflow_id)) is not None: | ||
return FileResponse(wdl) | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No workflow with ID {workflow_id}") | ||
|
||
@workflow_router.get("/{workflow_id}", dependencies=[authz_middleware.dep_public_endpoint()]) | ||
def workflow_item(workflow_id: str) -> WorkflowDefinition: | ||
if (wf := workflow_set.get_workflow(workflow_id)) is not None: | ||
return wf | ||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"No workflow with ID {workflow_id}") | ||
|
||
return workflow_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