use serde::Serialize;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct ServerHandle {
pub http_addr: Option<std::net::SocketAddr>,
pub https_addr: Option<std::net::SocketAddr>,
pub cert_reloader: Option<std::sync::Arc<crate::tls::ReloadableCertResolver>>,
}
impl ServerHandle {
pub fn reload_tls_certs(&self, cert_path: &str, key_path: &str) -> Result<(), String> {
match &self.cert_reloader {
Some(reloader) => reloader
.reload_from_paths(cert_path, key_path)
.map_err(|e| e.to_string()),
None => Err("no HTTPS listener active; cert reload not available".to_owned()),
}
}
}
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct ServerControl {}
impl ServerControl {
pub fn new() -> Self {
Self {}
}
}
#[derive(Clone, Copy, Debug, Serialize)]
pub enum ServerState {
Starting,
Running,
ShuttingDown,
Stopped,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub enum ReloadHint {
None,
Reload,
Restart,
}
impl From<apimock_config::ReloadHint> for ReloadHint {
fn from(value: apimock_config::ReloadHint) -> Self {
if value.requires_restart {
ReloadHint::Restart
} else if value.requires_reload {
ReloadHint::Reload
} else {
ReloadHint::None
}
}
}
impl From<ReloadHint> for apimock_config::ReloadHint {
fn from(value: ReloadHint) -> Self {
match value {
ReloadHint::None => apimock_config::ReloadHint::none(),
ReloadHint::Reload => apimock_config::ReloadHint::reload(),
ReloadHint::Restart => apimock_config::ReloadHint::restart(),
}
}
}