add method to endpoint
This commit is contained in:
@@ -5,7 +5,7 @@ mod stats;
|
||||
|
||||
pub use devices::{
|
||||
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::{
|
||||
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(
|
||||
State(state): State<AppState>,
|
||||
AxumPath(device_id): AxumPath<String>,
|
||||
|
||||
@@ -12,7 +12,7 @@ pub use commands::{list_agents, run_command};
|
||||
pub use control::{
|
||||
EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse,
|
||||
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,
|
||||
revoke_agent, revoke_enroll_token, set_agent_nickname, state_stats, wake_fleet_device,
|
||||
};
|
||||
|
||||
@@ -104,7 +104,7 @@ fn control_api_routes() -> Router<AppState> {
|
||||
)
|
||||
.route(
|
||||
"/api/v1/control/devices/{device_id}",
|
||||
axum::routing::delete(api::forget_known_device),
|
||||
get(api::get_known_device).delete(api::forget_known_device),
|
||||
)
|
||||
.route(
|
||||
"/api/v1/control/devices/{device_id}/merge",
|
||||
|
||||
@@ -216,7 +216,7 @@ impl Store {
|
||||
input: DeviceIdentifierInput,
|
||||
) -> Result<Option<KnownDevice>> {
|
||||
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!(
|
||||
"SELECT device_id FROM device_identifiers WHERE identifier_key = ?1",
|
||||
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>> {
|
||||
sqlx::query_as!(
|
||||
EnrollTokenRow,
|
||||
|
||||
Reference in New Issue
Block a user