feat(#2302): migrate dashboard to the single hive-host-sock Ident newtype
This commit is contained in:
parent
384dcae5f4
commit
1286029947
10 changed files with 37 additions and 210 deletions
|
|
@ -23,7 +23,7 @@ use axum::extract::{Form, Query};
|
|||
use axum::response::{IntoResponse, Response};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{error_response, idents::PlainIdent};
|
||||
use super::{Ident, error_response};
|
||||
use crate::coordinator::Coordinator;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -104,17 +104,14 @@ fn account_name_from_filename(fname: &str) -> Option<String> {
|
|||
|
||||
pub(super) async fn get_matrix_accounts(Query(q): Query<MatrixAccountsQuery>) -> Response {
|
||||
let agent = q.agent.trim();
|
||||
// Agent names are simple identifiers; reject anything else so a crafted
|
||||
// `agent` can't escape the per-agent state root via path components.
|
||||
if agent.is_empty()
|
||||
|| !agent
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||
{
|
||||
// Validate through the single `Ident` type so a crafted `agent` can't
|
||||
// escape the per-agent state root via path components — the same guard
|
||||
// every other agent-path builder goes through.
|
||||
let Ok(agent) = Ident::parse(agent) else {
|
||||
return error_response(&format!("matrix-accounts: invalid agent name {agent:?}"));
|
||||
}
|
||||
};
|
||||
|
||||
let dir = Coordinator::agent_notes_dir(agent);
|
||||
let dir = Coordinator::agent_notes_dir(agent.as_str());
|
||||
let (snapshot, as_of_unix) = read_accounts_snapshot(&dir);
|
||||
let mut accounts = Vec::new();
|
||||
match std::fs::read_dir(&dir) {
|
||||
|
|
@ -185,10 +182,10 @@ pub(super) async fn post_matrix_account_login(Form(f): Form<MatrixLoginForm>) ->
|
|||
let agent = f.agent.trim();
|
||||
let account = f.account.trim();
|
||||
let homeserver = f.homeserver.trim().trim_end_matches('/');
|
||||
let Ok(agent) = PlainIdent::parse(agent) else {
|
||||
let Ok(agent) = Ident::parse(agent) else {
|
||||
return error_response(&format!("matrix-account-login: invalid agent {agent:?}"));
|
||||
};
|
||||
let Ok(account) = PlainIdent::parse(account) else {
|
||||
let Ok(account) = Ident::parse(account) else {
|
||||
return error_response(&format!(
|
||||
"matrix-account-login: invalid account {account:?}"
|
||||
));
|
||||
|
|
@ -281,7 +278,7 @@ struct GithubAccountResult {
|
|||
pub(super) async fn post_github_account(Form(f): Form<GithubAccountForm>) -> Response {
|
||||
let agent = f.agent.trim();
|
||||
let token = f.token.trim();
|
||||
let Ok(agent) = PlainIdent::parse(agent) else {
|
||||
let Ok(agent) = Ident::parse(agent) else {
|
||||
return error_response(&format!("github-account: invalid agent {agent:?}"));
|
||||
};
|
||||
if token.is_empty() {
|
||||
|
|
@ -313,7 +310,7 @@ struct GithubAccountStatus {
|
|||
/// Never returns the token itself.
|
||||
pub(super) async fn get_github_account(Query(q): Query<GithubAccountQuery>) -> Response {
|
||||
let agent = q.agent.trim();
|
||||
let Ok(agent) = PlainIdent::parse(agent) else {
|
||||
let Ok(agent) = Ident::parse(agent) else {
|
||||
return error_response(&format!("github-account: invalid agent {agent:?}"));
|
||||
};
|
||||
let present = Coordinator::agent_notes_dir(agent.as_str())
|
||||
|
|
|
|||
Loading…
Reference in a new issue