Skip to main content

hyperlane_plugin_maintenance/
struct.rs

1use super::*;
2
3/// Configuration for [`MaintenancePlugin`].
4#[derive(Clone, Data, Debug, Eq, PartialEq)]
5pub struct MaintenanceConfig {
6    /// Initial operating mode on startup.
7    #[get(type(copy))]
8    pub(crate) initial_mode: MaintenanceMode,
9    /// Exact paths always exempted (for example `"/healthz"`, `"/readyz"`).
10    pub(crate) exempt_paths: Vec<String>,
11    /// Segment-bounded path prefixes always exempted.
12    pub(crate) exempt_prefixes: Vec<String>,
13    /// Optional bypass header name (lowercased internally).
14    pub(crate) bypass_header: String,
15    /// Optional secret bypass tokens admitted via `bypass_header`.
16    pub(crate) bypass_tokens: Vec<String>,
17    /// Rejection HTTP status code (default `503 Service Unavailable`).
18    #[get(type(copy))]
19    pub(crate) status: HttpStatus,
20    /// Optional `Retry-After` header value in seconds.
21    #[get(type(copy))]
22    pub(crate) retry_after_secs: Option<u64>,
23    /// `Content-Type` header emitted on rejected responses.
24    pub(crate) content_type: String,
25    /// Body bytes emitted in full maintenance mode.
26    pub(crate) maintenance_body: Vec<u8>,
27    /// Body bytes emitted in read-only mode.
28    pub(crate) read_only_body: Vec<u8>,
29}
30
31/// Lock-free compiled maintenance gate backing [`MaintenanceHook`].
32#[derive(Debug)]
33pub struct MaintenancePlugin {
34    /// Retained source configuration.
35    pub(crate) config: MaintenanceConfig,
36    /// Live atomic operating mode (`Active` / `ReadOnly` / `Maintenance`).
37    pub(crate) mode: AtomicU8,
38    /// Lowercased bypass header name.
39    pub(crate) bypass_header_lower: String,
40    /// Bypass token bytes for constant-time matching.
41    pub(crate) bypass_tokens: Box<[Box<[u8]>]>,
42    /// Small inline exact exempt path slice.
43    pub(crate) exempt_small: Box<[String]>,
44    /// Large exact exempt path hash set.
45    pub(crate) exempt_set: Option<HashSetXxHash3_64<String>>,
46    /// Normalized exempt prefixes.
47    pub(crate) exempt_prefixes: Box<[String]>,
48    /// Prebuilt `503` wire response for full maintenance mode.
49    pub(crate) maintenance_wire: Vec<u8>,
50    /// Prebuilt `503` wire response for read-only mode.
51    pub(crate) read_only_wire: Vec<u8>,
52}
53
54/// Opt-in request middleware enforcing live maintenance and read-only windows.
55#[derive(Clone, Copy, Debug, Default)]
56#[hyperlane::request_middleware(-109)]
57pub struct MaintenanceHook;