Skip to main content

assay_workflow/api/
mod.rs

1pub mod activities;
2pub mod events;
3pub mod namespaces;
4pub mod openapi;
5pub mod public;
6pub mod queues;
7pub mod schedules;
8pub mod tasks;
9pub mod workers;
10pub mod workflow_tasks;
11pub mod workflows;
12
13use std::sync::Arc;
14
15use axum::Router;
16
17use crate::ctx::WorkflowCtx;
18use crate::store::WorkflowStore;
19
20/// Build the workflow HTTP API router. The `gate` argument is the
21/// wire-boundary auth layer; the embedder supplies it as a closure
22/// that wraps the authed portion of the router (typically
23/// `|r| r.layer(my_auth_middleware)`). The type signature makes the
24/// gate **non-optional** — you cannot construct an unauthenticated
25/// workflow router.
26///
27/// The closure receives only the authed portion. `health`, `version`,
28/// `openapi.json`, and `docs` are merged outside the gate so probes
29/// can reach them without a bearer token.
30pub fn router<S, F>(state: Arc<WorkflowCtx<S>>, gate: F) -> Router
31where
32    S: WorkflowStore,
33    F: FnOnce(Router<Arc<WorkflowCtx<S>>>) -> Router<Arc<WorkflowCtx<S>>>,
34{
35    let authed_api = Router::new()
36        .nest("/api/v1/engine/workflow", api_v1_router::<S>())
37        .nest("/api/v1/engine/workflow", events::router::<S>());
38    let gated = gate(authed_api);
39
40    let public_api = Router::new().nest("/api/v1/engine/workflow", public::router::<S>());
41
42    let app = gated.merge(public_api).merge(openapi::router::<S>());
43
44    app.with_state(state)
45}
46
47fn api_v1_router<S: WorkflowStore>() -> Router<Arc<WorkflowCtx<S>>> {
48    Router::new()
49        .merge(workflows::router::<S>())
50        .merge(activities::router::<S>())
51        .merge(workflow_tasks::router::<S>())
52        .merge(tasks::router::<S>())
53        .merge(schedules::router::<S>())
54        .merge(workers::router::<S>())
55        .merge(namespaces::router::<S>())
56        .merge(queues::router::<S>())
57}