Something went wrong. Try again.
POC : Observability infrastructure managment
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697use std::future::Future;
use serde::Deserialize;use topcoat::context::Cx;use topcoat::router::{content::Form, href, page};use topcoat::view::{View, ViewExt, view};use topcoat::Result;
use crate::deploy::{destroy_all, destroy_hub, destroy_satellite};use crate::ui::app;
#[derive(Debug, Deserialize)]pub struct DestroyForm { pub target: String, #[serde(default)] pub name: String, #[serde(default)] pub confirm: String,}
#[page(POST)]pub async fn action(cx: &Cx, Form(form): Form<DestroyForm>) -> Result<impl View + use<'_>> { if form.confirm != "destroy" { return Ok(view! { <section class="page-hero"> <h1>"Destroy cancelled"</h1> <p class="lede">"Tick the confirmation (confirm=destroy) to continue."</p> </section> <div class="panel"> <div class="err">"Confirmation missing — nothing was destroyed."</div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Overview"</a> </div> </div> } .boxed()); }
let cfg = app(cx).config_snapshot(); let target = form.target.clone(); let name = form.name.clone();
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<String> { match target.as_str() { "hub" => { destroy_hub(&cfg)?; Ok(format!("Hub destroyed on {}", cfg.hub.host)) } "satellite" => { if name.is_empty() { anyhow::bail!("name required for target=satellite"); } destroy_satellite(&cfg, &name)?; Ok(format!("Satellite {name} destroyed")) } "all" => { destroy_all(&cfg)?; Ok("Hub + all satellites destroyed".into()) } other => anyhow::bail!("unknown target: {other}"), } }) .await .map_err(|e| topcoat::Error::msg(e.to_string()))?;
match result { Ok(msg) => Ok(view! { <section class="page-hero"> <p class="crumb"> <a href=(href!(super::home))>"Overview"</a> <span class="sep">"/"</span> <span>"Destroy"</span> </p> <h1>"Destroyed"</h1> </section> <div class="panel"> <div class="ok-box">(msg.clone())</div> <p class="meta">"Compose down -v, sope images, remote directory — no sope traces left on the target."</p> <div class="actions"> <a class="btn" href=(href!(super::home))>"Overview"</a> </div> </div> } .boxed()), Err(e) => Ok(view! { <section class="page-hero"><h1>"Destroy failed"</h1></section> <div class="panel"> <div class="err"><pre class="log">(format!("{e:#}"))</pre></div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Overview"</a> </div> </div> } .boxed()), }}