Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: accounts handlers take their own sub-state via FromRef

This commit is contained in:
atlas 2026-11-28 01:36:20 +01:00 • committed by mara
commit 5e81895a3b
2 changed files with 147 additions and 77 deletions

View file

@ -100,6 +100,14 @@ pub(crate) fn render(declaration: &swarm_wire::wanted::HiveWanted) -> Vec<AgentD
pub(crate) fn swarm_hive(
state: &AppState,
hive: &str,
) -> Result<String, (axum::http::StatusCode, String)> {
hive_in(&state.hives, hive)
}
/// [`swarm_hive`] over the hive list alone, for a caller that holds only that.
pub(crate) fn hive_in(
hives: &[crate::routes::hives::HiveEntry],
hive: &str,
) -> Result<String, (axum::http::StatusCode, String)> {
let hive = hive_types::Ident::parse(hive)
.map_err(|reason| (axum::http::StatusCode::BAD_REQUEST, reason.to_owned()))?
@ -107,7 +115,7 @@ pub(crate) fn swarm_hive(
// Shaped like a hive name, and actually one. Same two checks
// `create_agent` makes, for the same reason: a typo otherwise publishes a
// declaration under a key no hive will ever read.
if !state.hives.iter().any(|h| h.name == hive) {
if !hives.iter().any(|h| h.name == hive) {
return Err((
axum::http::StatusCode::BAD_REQUEST,
format!("{hive:?} is not a hive in this swarm"),

View file

@ -628,7 +628,14 @@ pub(crate) fn spawn_reconcile(
/// The connected queue client, or the problem.
pub(crate) fn queue(state: &AppState) -> Result<async_nats::Client, (StatusCode, String)> {
let status = state.status.as_ref().ok_or_else(|| {
queue_of(state.status.as_ref())
}
/// [`queue`] over the status reader alone, for a caller that holds only that.
pub(crate) fn queue_of(
status: Option<&Arc<crate::status::StatusReader>>,
) -> Result<async_nats::Client, (StatusCode, String)> {
let status = status.ok_or_else(|| {
(
StatusCode::SERVICE_UNAVAILABLE,
"no swarm queue is configured on this host".to_owned(),