Add machine deletion API with uninstall command support

- Add AdminCommand message to protobuf (uninstall, restart, update)
- Add DELETE /api/machines/:agent_id endpoint with options:
  - ?uninstall=true - send uninstall command to online agent
  - ?export=true - return session history before deletion
- Add GET /api/machines/:agent_id/history endpoint for history export
- Add GET /api/machines endpoint to list all machines
- Handle AdminCommand in agent session handler
- Handle ADMIN_UNINSTALL error in agent main loop to trigger uninstall

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
AZ Computer Guru
2025-12-29 19:15:16 -07:00
parent 05ab8a8bf4
commit dc7b7427ce
8 changed files with 380 additions and 6 deletions

View File

@@ -105,3 +105,22 @@ pub async fn get_events_by_type(
.fetch_all(pool)
.await
}
/// Get all events for a machine (by joining through sessions)
pub async fn get_events_for_machine(
pool: &PgPool,
machine_id: Uuid,
) -> Result<Vec<SessionEvent>, sqlx::Error> {
sqlx::query_as::<_, SessionEvent>(
r#"
SELECT e.id, e.session_id, e.event_type, e.timestamp, e.viewer_id, e.viewer_name, e.details, e.ip_address::text as ip_address
FROM connect_session_events e
JOIN connect_sessions s ON e.session_id = s.id
WHERE s.machine_id = $1
ORDER BY e.timestamp DESC
"#
)
.bind(machine_id)
.fetch_all(pool)
.await
}

View File

@@ -96,3 +96,16 @@ pub async fn get_recent_sessions(
.fetch_all(pool)
.await
}
/// Get all sessions for a machine (for history export)
pub async fn get_sessions_for_machine(
pool: &PgPool,
machine_id: Uuid,
) -> Result<Vec<DbSession>, sqlx::Error> {
sqlx::query_as::<_, DbSession>(
"SELECT * FROM connect_sessions WHERE machine_id = $1 ORDER BY started_at DESC"
)
.bind(machine_id)
.fetch_all(pool)
.await
}