Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/swarmctl/src/forge.rs
atlas 44caa72c19 swarmctl: interactive setup walks the first-run ceremony
swarmctl setup with no subcommand checks the setup status first, then takes the open steps one at a time: prompts for input, shows a running action as one live line, prints the store keys, root token and new password under a warning until the operator confirms, and names the deploy option for a step this host cannot do. It calls the code of bao init, bao grant-bootstrap, user add, forge make-admin, agent create, agent permissions set and agent set-state. Refuses without root or a terminal.
2026-11-08 18:11:39 +01:00

41 lines
1.5 KiB
Rust

//! `swarmctl forge make-admin` — make an existing human forge account a site
//! admin, through the swarm-controller over the forge's admin API.
//!
//! Unlike the `agent` verbs this one waits: the controller answers with what
//! it found. Same round trip as [`crate::agent`], over the controller's unix
//! socket.
use anyhow::{Context as _, Result};
use swarm_controller_api::forge::{ForgeAdminChange, MakeForgeAdminResponse};
use crate::agent::{parse_ident, post};
use crate::remote::Target;
/// Run `swarmctl forge make-admin`.
///
/// Synchronous for the same reason `agent create` is.
pub(crate) fn make_admin(target: &Target, name: &str) -> Result<()> {
println!("{}", request_admin(target, name)?);
Ok(())
}
/// The round trip of [`make_admin`]: the sentence it prints, not printed.
pub(crate) fn request_admin(target: &Target, name: &str) -> Result<String> {
let name = parse_ident(name, "user name")?;
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.context("starting a tokio runtime for the controller request")?;
let resp: MakeForgeAdminResponse = rt.block_on(post(
target,
&format!("/api/forge/users/{name}/admin"),
&serde_json::json!({}),
"forge-make-admin",
))?;
Ok(match resp.change {
ForgeAdminChange::Promoted => format!("forge: {name:?} is now a site admin"),
ForgeAdminChange::AlreadyAdmin => format!("forge: {name:?} was already a site admin"),
})
}