use super::operator::OperatorContext;
use crate::utils::error::Result;
use crate::validation::AndonSignal;
pub struct GateResult {
pub gate_name: String,
pub passed: bool,
pub signal: AndonSignal,
}
pub trait ProofGate {
fn name(&self) -> &str;
fn validate(&self, ctx: &OperatorContext) -> Result<GateResult>;
}
pub struct ObservabilityPresentGate;
impl ProofGate for ObservabilityPresentGate {
fn name(&self) -> &str {
"observability-present"
}
fn validate(&self, _ctx: &OperatorContext) -> Result<GateResult> {
Ok(GateResult {
gate_name: self.name().to_string(),
passed: true,
signal: AndonSignal::Green,
})
}
}
use std::marker::PhantomData;
#[derive(Debug, Clone)]
pub struct Pending;
#[derive(Debug, Clone)]
pub struct Hot;
#[derive(Debug, Clone)]
pub struct Spent;
#[derive(Debug, Clone)]
pub struct UMotion<State> {
pub payload: String, _state: PhantomData<State>,
}
impl UMotion<Pending> {
pub fn new(payload: String) -> Self {
Self {
payload,
_state: PhantomData,
}
}
pub fn admit(self) -> Result<UMotion<Hot>> {
tracing::info!("UniverseOS: Admitting motion for payload {}", self.payload);
Ok(UMotion {
payload: self.payload,
_state: PhantomData,
})
}
}
impl UMotion<Hot> {
pub fn execute(self) -> UMotion<Spent> {
tracing::info!("UniverseOS: Executing motion for payload {}", self.payload);
UMotion {
payload: self.payload,
_state: PhantomData,
}
}
}
pub struct UniverseOsTypestateGate;
impl ProofGate for UniverseOsTypestateGate {
fn name(&self) -> &str {
"universeos-typestate-admission"
}
fn validate(&self, ctx: &OperatorContext) -> Result<GateResult> {
let pending = UMotion::<Pending>::new(ctx.artifact_id.clone());
let hot = pending.admit()?;
let _spent = hot.execute();
Ok(GateResult {
gate_name: self.name().to_string(),
passed: true,
signal: AndonSignal::Green,
})
}
}