use 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) -> Result> { if form.confirm != "destroy" { return Ok(view! {

"Destroy cancelled"

"Tick the confirmation (confirm=destroy) to continue."

"Confirmation missing — nothing was destroyed."
} .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 { 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! {

"Overview" "/" "Destroy"

"Destroyed"

(msg.clone())

"Compose down -v, sope images, remote directory — no sope traces left on the target."

} .boxed()), Err(e) => Ok(view! {

"Destroy failed"

(format!("{e:#}"))
} .boxed()), } }