hyperlane-plugin-maintenance 23.3.0

A lock-free atomic maintenance and read-only mode plugin for the Hyperlane framework with live zero-restart switching, path and constant-time bypass-token exemptions, Retry-After headers, and prebuilt 503 wire responses.
Documentation
use super::*;

/// Configuration for [`MaintenancePlugin`].
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct MaintenanceConfig {
    /// Initial operating mode on startup.
    #[get(type(copy))]
    pub(crate) initial_mode: MaintenanceMode,
    /// Exact paths always exempted (for example `"/healthz"`, `"/readyz"`).
    pub(crate) exempt_paths: Vec<String>,
    /// Segment-bounded path prefixes always exempted.
    pub(crate) exempt_prefixes: Vec<String>,
    /// Optional bypass header name (lowercased internally).
    pub(crate) bypass_header: String,
    /// Optional secret bypass tokens admitted via `bypass_header`.
    pub(crate) bypass_tokens: Vec<String>,
    /// Rejection HTTP status code (default `503 Service Unavailable`).
    #[get(type(copy))]
    pub(crate) status: HttpStatus,
    /// Optional `Retry-After` header value in seconds.
    #[get(type(copy))]
    pub(crate) retry_after_secs: Option<u64>,
    /// `Content-Type` header emitted on rejected responses.
    pub(crate) content_type: String,
    /// Body bytes emitted in full maintenance mode.
    pub(crate) maintenance_body: Vec<u8>,
    /// Body bytes emitted in read-only mode.
    pub(crate) read_only_body: Vec<u8>,
}

/// Lock-free compiled maintenance gate backing [`MaintenanceHook`].
#[derive(Debug)]
pub struct MaintenancePlugin {
    /// Retained source configuration.
    pub(crate) config: MaintenanceConfig,
    /// Live atomic operating mode (`Active` / `ReadOnly` / `Maintenance`).
    pub(crate) mode: AtomicU8,
    /// Lowercased bypass header name.
    pub(crate) bypass_header_lower: String,
    /// Bypass token bytes for constant-time matching.
    pub(crate) bypass_tokens: Box<[Box<[u8]>]>,
    /// Small inline exact exempt path slice.
    pub(crate) exempt_small: Box<[String]>,
    /// Large exact exempt path hash set.
    pub(crate) exempt_set: Option<HashSetXxHash3_64<String>>,
    /// Normalized exempt prefixes.
    pub(crate) exempt_prefixes: Box<[String]>,
    /// Prebuilt `503` wire response for full maintenance mode.
    pub(crate) maintenance_wire: Vec<u8>,
    /// Prebuilt `503` wire response for read-only mode.
    pub(crate) read_only_wire: Vec<u8>,
}

/// Opt-in request middleware enforcing live maintenance and read-only windows.
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-109)]
pub struct MaintenanceHook;