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

View file

@ -12,9 +12,9 @@ use serde::Deserialize;
use swarm_secret_client::github;
use utoipa::ToSchema;
use super::AccountsState;
use super::linked_accounts::link;
use crate::routes::agents::swarm_hive;
use crate::routes::{AppState, error_problem};
use crate::routes::error_problem;
/// The token to store for one agent.
///
@ -44,11 +44,11 @@ pub struct PutGithubAccountRequest {
tag = "agents"
)]
pub async fn put_github_account(
State(state): State<AppState>,
State(state): State<AccountsState>,
axum::extract::Path((hive, agent)): axum::extract::Path<(String, String)>,
Json(req): Json<PutGithubAccountRequest>,
) -> Result<StatusCode, problem_details::ProblemDetails> {
let hive = swarm_hive(&state, &hive).map_err(|(s, d)| error_problem(s, &d))?;
let hive = state.hive(&hive).map_err(|(s, d)| error_problem(s, &d))?;
let agent = hive_types::Ident::parse(&agent)
.map_err(|reason| error_problem(StatusCode::BAD_REQUEST, reason))?
.into_string();
@ -112,12 +112,9 @@ mod tests {
assert!(credential(&request("")).is_err());
}
/// Bare-minimum `AppState`, as `forge_account`'s tests build it.
fn state(store: &Arc<FakeStore>) -> crate::routes::AppState {
crate::routes::AppState {
accounts: Accounts::Fake(Arc::clone(store)),
..crate::routes::AppState::for_test()
}
/// A handler test's state: one hive, no queue, `store` as the account store.
fn state(store: &Arc<FakeStore>) -> crate::accounts::AccountsState {
crate::accounts::AccountsState::for_test(Accounts::Fake(Arc::clone(store)))
}
async fn put(