1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Axum HTTP API for Chronon (`/api/chronon/*`).
//!
//! Mounts job, run, and script routes on a host Axum server. Handlers delegate to
//! [`chronon_runtime::CoordinatorService`] and read script metadata from
//! [`chronon_executor::ScriptRegistry`].
//!
//! # Features
//!
//! - **AdminAuth** — host-supplied [`AdminAuth`] via [`ChrononStateBuilder`]; lab helpers
//! [`StaticTokenAdminAuth`] / [`AllowAllAdminAuth`]. Production identity belongs to Higgs.
//! - **`CHRONON_REQUIRE_ADMIN_AUTH`** — when set, [`ChrononStateBuilder::build`] and
//! [`RequireAdmin`] fail closed without a verifier.
//! - **External actor policy** — HTTP upsert rejects System-shaped `actor_json`
//! ([`RejectExternalSystemActor`](chronon_core::RejectExternalSystemActor)).
//! - **Error hygiene** — HTTP envelopes sanitize/redact credentials in error strings.
//!
//! # Security
//!
//! Wrap-before-public-bind: nest under [`API_PREFIX`], install [`AdminAuth`] (or host middleware),
//! and set `CHRONON_REQUIRE_ADMIN_AUTH=1` before exposing the API. See repository `SECURITY.md`
//! and the `axum_auth_wrap` example.
//!
//! # Routes
//!
//! - `GET/POST /jobs/*` — list, upsert (by `job_name`), pause, resume, run now
//! - `GET /runs/*` — list (limit capped at 1000) and fetch runs
//! - `GET /scripts` — list registered scripts
//! - `GET /jobs/{id}/revisions` — revision metadata with actor/params redacted
//!
//! All responses use the [`ApiResponse`] envelope (`success`, `data`, `error`).
//! [`UpsertJobRequest::script_name`] must exist in the registry or upsert returns 400.
//! Concurrency, timeout, and retry knobs are clamped to production ceilings.
//!
//! # Remote HTTP clients
//!
//! Mount this router on an embedded or coordinator–worker host **behind host auth**, then point
//! [`chronon_runtime::RemoteCoordinatorClient`] at `{base_url}` (paths under
//! [`API_PREFIX`]). See the `chronon` crate [Remote HTTP client](https://docs.rs/uf-chronon/latest/chronon/index.html#remote-http-client) section.
//!
//! # Examples
//!
//! Completed setup with [`RequireAdmin`] / [`StaticTokenAdminAuth`]:
//!
//! ```
//! use std::sync::Arc;
//! use axum::extract::FromRef;
//! use axum::Router;
//! use chronon_axum::{
//! chronon_router, ChrononState, StaticTokenAdminAuth, API_PREFIX,
//! };
//! use chronon_backend_mem::InMemorySchedulerStore;
//! use chronon_core::{Result as ChrononResult, ScriptContext};
//! use chronon_executor::{ScriptDescriptor, ScriptRegistry};
//! use chronon_runtime::CoordinatorService;
//!
//! fn noop(
//! _ctx: Box<dyn ScriptContext>,
//! _params: serde_json::Value,
//! ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ChrononResult<()>> + Send>> {
//! Box::pin(async { Ok(()) })
//! }
//!
//! #[derive(Clone)]
//! struct AppState {
//! chronon: ChrononState,
//! }
//!
//! impl FromRef<AppState> for ChrononState {
//! fn from_ref(state: &AppState) -> Self {
//! state.chronon.clone()
//! }
//! }
//!
//! # fn mount() -> chronon_core::Result<Router<AppState>> {
//! let store = Arc::new(InMemorySchedulerStore::new());
//! let coordinator = Arc::new(CoordinatorService::new(store));
//! let registry = Arc::new({
//! let mut r = ScriptRegistry::new();
//! r.register(&ScriptDescriptor::new("demo", noop));
//! r
//! });
//! let chronon = ChrononState::builder(coordinator, registry)
//! .admin_auth(Arc::new(StaticTokenAdminAuth::new("lab-token")))
//! .require_admin_auth(true)
//! .build()?;
//! Ok(Router::new()
//! .nest(API_PREFIX, chronon_router::<AppState>())
//! .with_state(AppState { chronon }))
//! # }
//! ```
//!
//! Runnable:
//! `cargo run -p uf-chronon --example axum_host --features mem,axum`,
//! `axum_auth_wrap`, and
//! `remote_http_client` (client against a nested router).
use ;
pub use ;
pub use ;
pub use ApiResponse;
pub use ;
/// API mount prefix for host routers (e.g. `nest(API_PREFIX, chronon_router())`).
pub const API_PREFIX: &str = "/api/chronon";
/// Create the Chronon API router with job, run, and script routes.
///
/// Host state `S` must implement [`FromRef<S>`] for [`ChrononState`]. Nest under
/// [`API_PREFIX`] (`/api/chronon`) so [`chronon_runtime::RemoteCoordinatorClient`] paths match.
///
/// Handlers extract [`RequireAdmin`]. Install [`AdminAuth`] on [`ChrononState`] (or set
/// `CHRONON_REQUIRE_ADMIN_AUTH=1` and fail closed) before public bind. See `SECURITY.md`.
///
/// See the crate-level example (RequireAdmin + StaticTokenAdminAuth).