use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(deny_unknown_fields)]
pub struct WebIngressRoute {
pub method: String,
pub path: String,
pub route_id: String,
}
impl WebIngressRoute {
pub fn new(method: &str, path: &str, route_id: &str) -> Self {
Self {
method: method.to_owned(),
path: path.to_owned(),
route_id: route_id.to_owned(),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WebIngressRouteManifest {
routes: Vec<WebIngressRoute>,
}
impl WebIngressRouteManifest {
pub(crate) fn new(mut routes: Vec<WebIngressRoute>) -> Self {
routes.sort_unstable();
Self { routes }
}
pub fn routes(&self) -> &[WebIngressRoute] {
&self.routes
}
pub fn ensure_equivalent(&self, replica: &Self) -> Result<(), WebIngressReplicaMismatch> {
if self == replica {
Ok(())
} else {
Err(WebIngressReplicaMismatch)
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct WebIngressReplicaMismatch;
impl fmt::Display for WebIngressReplicaMismatch {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("same-port Web Ingress replicas have different route manifests")
}
}
impl std::error::Error for WebIngressReplicaMismatch {}