feat(#2014): hivectl open verb + Urls host request for web surfaces
This commit is contained in:
parent
c2ba841932
commit
cae1dd8147
6 changed files with 200 additions and 32 deletions
|
|
@ -155,16 +155,12 @@ async fn dispatch(req: &HostRequest, coord: Arc<Coordinator>) -> HostResponse {
|
|||
.collect();
|
||||
HostResponse::agent_statuses(rows)
|
||||
}
|
||||
// The hive domain is injected into c0re's service env by
|
||||
// hive-c0re.nix (`HYPERHIVE_HIVE_DOMAIN`); surface it so the
|
||||
// operator CLI can fill in this hive's own identity.
|
||||
HostRequest::HiveDomain => HostResponse::hive_domain(
|
||||
// Treat an empty env value as unset — otherwise the CLI
|
||||
// would emit `swarm.peers."" = …`, invalid nix.
|
||||
std::env::var("HYPERHIVE_HIVE_DOMAIN")
|
||||
.ok()
|
||||
.filter(|d| !d.is_empty()),
|
||||
),
|
||||
// The hive domain + per-surface public URLs are injected into
|
||||
// c0re's service env by hive-c0re.nix; surface them so the
|
||||
// operator CLI can fill in this hive's own identity (the
|
||||
// federation peer-config block) and open the web surfaces
|
||||
// (`hivectl open`).
|
||||
HostRequest::Urls => HostResponse::urls(hive_urls()),
|
||||
HostRequest::Pending => HostResponse::pending(coord.approvals.pending()?),
|
||||
HostRequest::Approve { id } => {
|
||||
actions::approve(coord.clone(), *id).await?;
|
||||
|
|
@ -261,7 +257,7 @@ async fn handle_restart_all() -> Result<HostResponse> {
|
|||
error: Some(errors.join("; ")),
|
||||
agents: Some(ok_agents),
|
||||
approvals: None,
|
||||
domain: None,
|
||||
urls: None,
|
||||
agent_statuses: None,
|
||||
})
|
||||
}
|
||||
|
|
@ -379,6 +375,25 @@ fn is_broad_scope(scope: &LifecycleScope) -> bool {
|
|||
scope.agents || scope.is_everything()
|
||||
}
|
||||
|
||||
/// Assemble this hive's domain + browser-facing web URLs from c0re's
|
||||
/// service env (injected by hive-c0re.nix). Each field is `None` when its
|
||||
/// surface isn't browser-reachable (domain unset, forge not behind the
|
||||
/// gateway, matrix GUI off), so the CLI can hint precisely instead of
|
||||
/// opening a dead link. Scheme matches the existing `HIVE_FORGE_PUBLIC_URL`
|
||||
/// convention (gateway terminates TLS, so https).
|
||||
fn hive_urls() -> hive_sh4re::HiveUrls {
|
||||
// Treat an empty env value as unset everywhere — an empty domain would
|
||||
// otherwise render `swarm.peers."" = …` (invalid nix) and `https:///`.
|
||||
let env = |k: &str| std::env::var(k).ok().filter(|v| !v.is_empty());
|
||||
let domain = env("HYPERHIVE_HIVE_DOMAIN");
|
||||
hive_sh4re::HiveUrls {
|
||||
home: domain.as_ref().map(|d| format!("https://{d}/")),
|
||||
forge: env("HIVE_FORGE_PUBLIC_URL"),
|
||||
matrix: env("HIVE_MATRIX_PUBLIC_URL"),
|
||||
domain,
|
||||
}
|
||||
}
|
||||
|
||||
async fn scoped_agents(scope: &LifecycleScope) -> Result<Vec<String>> {
|
||||
use std::collections::BTreeSet;
|
||||
let mut set: BTreeSet<String> = BTreeSet::new();
|
||||
|
|
@ -430,7 +445,7 @@ fn finish_lifecycle(ok_items: Vec<String>, errors: &[String]) -> HostResponse {
|
|||
error: Some(errors.join("; ")),
|
||||
agents: Some(ok_items),
|
||||
approvals: None,
|
||||
domain: None,
|
||||
urls: None,
|
||||
agent_statuses: None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue