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
//! The operator console for id_effect services: live fibers, supervision trees, metrics, health
//! and the log level, behind an `id_effect_authz` guard.
//!
//! # The API
//!
//! [`Console`] collects what the console shows and [`Console::router`] turns it into an Axum
//! router answering JSON under [`API_PREFIX`] (`/_console/api`) and the dashboard page at
//! `/_console`:
//!
//! | Route | Answers |
//! |---|---|
//! | `GET fibers` | every live fiber ([`FiberView`], from core `fiber_dump`, feature `fiber-registry`) |
//! | `GET supervisors` | the registered supervision trees ([`SupervisorsView`], from `which_children`) |
//! | `GET metrics` | the metric registry and the runtime fiber gauges ([`MetricView`]) |
//! | `GET health` | the [`HealthRegistry`](id_effect_axum::HealthRegistry) report (always `200`) |
//! | `GET log-level` | the reloadable `EnvFilter` and the `EffectLogger` minimum ([`LogLevelView`]) |
//! | `PUT log-level` | changes both without a restart ([`LogLevelChange`]) |
//! | `GET jobs` | per-queue counts and the newest jobs of a job queue (`JobsView`, feature `jobs`) |
//! | `POST jobs/{id}/retry` | a `dead` or `cancelled` job runs again now (`JobView`; `404` unknown id, `409` other state) |
//! | `POST jobs/{id}/cancel` | a `scheduled` or `failed` job is cancelled (`JobView`; `404` unknown id, `409` other state) |
//!
//! The two `POST` routes require `Content-Type: application/json` (`415` otherwise), so a
//! cross-site form cannot trigger them.
//!
//! # The dashboard
//!
//! The same router serves `GET /_console`: one static page (inline CSS and vanilla JavaScript,
//! compiled in with `include_str!`, no build step and nothing loaded from another origin) that
//! polls the API and shows the health checks, the log level with a form that changes it, the
//! supervision trees, the job queues (when the `jobs` feature and a queue are configured, with a
//! retry button on dead and cancelled jobs and a cancel button on scheduled and failed ones), the
//! live fibers and the metrics. It is behind the same guard as the API.
//!
//! # Security model
//!
//! There is no unguarded constructor: the only way to get the routes is
//! [`Console::router`], which takes an authorization [`Guard`](id_effect_authz::Guard) and puts it
//! in front of every console route **and** the console router's fallback, so a principal the
//! guard denies learns nothing about the API (`401` anonymous, `403` otherwise, Problem Details
//! body). The authentication layer that sets the principal runs outside the guard
//! (`Router::layer` on the merged app), as for any `id_effect_authz` route. Console answers carry
//! `Cache-Control: no-store`.
//!
//! [`ConsoleConfig`] is where the console listens. Bound to a loopback address it serves the local
//! machine only; on any other address [`ConsoleConfig::requires_guard`] is true: the guard must then
//! restrict the console to operators (a role or permission policy), while a loopback console may
//! use a lenient one such as `authenticated()`. The guard is required either way.
//!
//! ```
//! use std::net::{Ipv6Addr, SocketAddr};
//!
//! use id_effect_authz::{Guard, require_role};
//! use id_effect_console::{Console, ConsoleConfig};
//!
//! let config = ConsoleConfig::new(SocketAddr::from((Ipv6Addr::LOCALHOST, 9090)));
//! assert!(!config.requires_guard());
//!
//! let console: axum::Router = Console::new().router(Guard::new("console", require_role("operator")));
//! # let _ = console;
//! ```
//!
//! Tier `platform` (ADR 0010 Amendment 6): the Ledger reference app under
//! `examples/reference/` depends on it.
pub use ;
pub use ;
pub use ;
pub use ;
use ;
/// Where the console listens.