from-what now

This commit is contained in:
lda committed 2026-04-27 01:43:24 +07:00 Verified
1 parent d91b3dab77
commit 29f522e722
9 files changed
+564 -12

No files matched your search

+38 -4
View File
@@ -8,8 +8,8 @@ use tracing::{info, warn};
use crate::api::json_error;
use crate::runtime::{AppState, SessionEvent};
use crate::state::{
AgentDeviceObservation, AgentDeviceObservationInput, AuditEventInput, DeviceIdentifierInput,
KnownDeviceInput,
AgentDeviceObservationInput, AgentDeviceObservationView, AuditEventInput,
DeviceIdentifierInput, KnownDeviceInput,
};
#[derive(Debug, Deserialize)]
@@ -91,6 +91,11 @@ pub struct DeviceIdentifierRequest {
pub value: String,
}
#[derive(Debug, Deserialize)]
pub struct AttachObservationIdentifierRequest {
pub observation_key: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct KnownDeviceResponse {
pub device_id: String,
@@ -592,6 +597,33 @@ pub async fn attach_device_identifier(
}
}
pub async fn attach_observation_identifier(
State(state): State<AppState>,
AxumPath(device_id): AxumPath<String>,
Json(req): Json<AttachObservationIdentifierRequest>,
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
match state
.store
.attach_observation_identifier(&device_id, &req.observation_key)
.await
{
Ok(Some(device)) => Ok((StatusCode::OK, Json(known_device_response(device)))),
Ok(None) => Err(json_error(
StatusCode::NOT_FOUND,
"known_device_not_found",
"known device not found",
)),
Err(err) => {
warn!(error = %err, "failed to attach observation identifier");
Err(json_error(
StatusCode::BAD_REQUEST,
"attach_observation_identifier_failed",
&err.to_string(),
))
}
}
}
pub async fn upload_agent_observations(
State(state): State<AppState>,
Json(req): Json<UploadAgentObservationsRequest>,
@@ -648,7 +680,7 @@ pub async fn list_agent_observations(
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
match state
.store
.list_agent_observations(query.agent_id.as_deref(), query.limit.unwrap_or(500))
.list_agent_observation_views(query.agent_id.as_deref(), query.limit.unwrap_or(500))
.await
{
Ok(observations) => Ok((
@@ -696,7 +728,9 @@ pub async fn state_stats(
}
}
fn agent_observation_response(observation: AgentDeviceObservation) -> AgentDeviceObservation {
fn agent_observation_response(
observation: AgentDeviceObservationView,
) -> AgentDeviceObservationView {
observation
}
+4 -3
View File
@@ -11,9 +11,10 @@ pub use audit::list_audit_events;
pub use commands::{list_agents, run_command};
pub use control::{
EnrollTokenStatus, IssueEnrollTokenResponse, RevokeAgentResponse, RevokeEnrollTokenResponse,
StateStatsResponse, attach_device_identifier, create_known_device, enroll, forget_known_device,
healthz, issue_enroll_token, list_agent_observations, list_enroll_tokens, list_known_devices,
revoke_agent, revoke_enroll_token, set_agent_nickname, state_stats, upload_agent_observations,
StateStatsResponse, attach_device_identifier, attach_observation_identifier,
create_known_device, enroll, forget_known_device, healthz, issue_enroll_token,
list_agent_observations, list_enroll_tokens, list_known_devices, revoke_agent,
revoke_enroll_token, set_agent_nickname, state_stats, upload_agent_observations,
};
pub fn json_error(