add method to endpoint

This commit is contained in:
lda
2026-07-15 04:37:41 +07:00 Verified
parent cf515527af
commit 8a93250781
7 changed files with 29 additions and 9 deletions
+3
View File
@@ -0,0 +1,3 @@
allowBuilds:
esbuild: false
msw: false
+1 -1
View File
@@ -5,7 +5,7 @@ mod stats;
pub use devices::{ pub use devices::{
attach_device_identifier, create_known_device, detach_device_identifier, forget_known_device, attach_device_identifier, create_known_device, detach_device_identifier, forget_known_device,
list_known_devices, merge_known_device, get_known_device, list_known_devices, merge_known_device,
}; };
pub use enroll::{ pub use enroll::{
EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse, EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse,
@@ -111,6 +111,28 @@ pub async fn list_known_devices(
} }
} }
pub async fn get_known_device(
State(state): State<AppState>,
AxumPath(device_id): AxumPath<String>,
) -> Result<impl IntoResponse, ApiError> {
match state.store.get_known_device(&device_id).await {
Ok(Some(device)) => Ok((StatusCode::OK, Json(known_device_response(device)))),
Ok(None) => Err(ApiError::new(
StatusCode::NOT_FOUND,
"known_device_not_found",
"known device not found",
)),
Err(err) => {
warn!(error = %err, "failed to get known device");
Err(ApiError::new(
StatusCode::INTERNAL_SERVER_ERROR,
"get_known_device_failed",
err.to_string(),
))
}
}
}
pub async fn forget_known_device( pub async fn forget_known_device(
State(state): State<AppState>, State(state): State<AppState>,
AxumPath(device_id): AxumPath<String>, AxumPath(device_id): AxumPath<String>,
+1 -1
View File
@@ -12,7 +12,7 @@ pub use commands::{list_agents, run_command};
pub use control::{ pub use control::{
EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse, EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse,
StateStatsResponse, attach_device_identifier, create_known_device, detach_device_identifier, StateStatsResponse, attach_device_identifier, create_known_device, detach_device_identifier,
enroll, forget_known_device, healthz, issue_enroll_token, list_enroll_tokens, enroll, forget_known_device, get_known_device, healthz, issue_enroll_token, list_enroll_tokens,
list_fleet_devices, list_known_devices, merge_known_device, refresh_fleet_devices, list_fleet_devices, list_known_devices, merge_known_device, refresh_fleet_devices,
revoke_agent, revoke_enroll_token, set_agent_nickname, state_stats, wake_fleet_device, revoke_agent, revoke_enroll_token, set_agent_nickname, state_stats, wake_fleet_device,
}; };
+1 -1
View File
@@ -104,7 +104,7 @@ fn control_api_routes() -> Router<AppState> {
) )
.route( .route(
"/api/v1/control/devices/{device_id}", "/api/v1/control/devices/{device_id}",
axum::routing::delete(api::forget_known_device), get(api::get_known_device).delete(api::forget_known_device),
) )
.route( .route(
"/api/v1/control/devices/{device_id}/merge", "/api/v1/control/devices/{device_id}/merge",
@@ -216,7 +216,7 @@ impl Store {
input: DeviceIdentifierInput, input: DeviceIdentifierInput,
) -> Result<Option<KnownDevice>> { ) -> Result<Option<KnownDevice>> {
let identifier = normalize_device_identifier(input)?; let identifier = normalize_device_identifier(input)?;
let identifier_key = normalized_identifier_key_owned(identifier); let identifier_key = identifier.identifier_key;
let device_id = sqlx::query_scalar!( let device_id = sqlx::query_scalar!(
"SELECT device_id FROM device_identifiers WHERE identifier_key = ?1", "SELECT device_id FROM device_identifiers WHERE identifier_key = ?1",
identifier_key identifier_key
@@ -70,11 +70,6 @@ pub fn normalize_device_identifier(
}) })
} }
#[cfg_attr(not(test), allow(dead_code))]
pub fn normalized_identifier_key_owned(identifier: NormalizedDeviceIdentifier) -> String {
identifier.identifier_key
}
pub async fn list_enroll_token_rows(pool: &SqlitePool) -> Result<Vec<EnrollTokenRow>> { pub async fn list_enroll_token_rows(pool: &SqlitePool) -> Result<Vec<EnrollTokenRow>> {
sqlx::query_as!( sqlx::query_as!(
EnrollTokenRow, EnrollTokenRow,