CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m5s
CI / Deploy MCP (push) Successful in 2m54s
CI / Deploy Dashboard (push) Successful in 6m29s
CI / Deploy Agent (push) Successful in 8m16s
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
//! A target's Siemens controllers (SPS item 4a), read from the agent's
|
|
//! `/api/v1/targets/{id}/devices` and changed with the target.
|
|
|
|
use compliance_core::device_check::{DeviceCheck, DeviceLookup};
|
|
use compliance_core::models::PlcDevice;
|
|
use dioxus::prelude::*;
|
|
|
|
/// Target `id`'s devices, each with the Siemens advisories naming it.
|
|
#[server]
|
|
pub async fn fetch_devices(id: String) -> Result<Vec<DeviceCheck>, ServerFnError> {
|
|
super::agent_client::data(
|
|
super::agent_client::agent_get(&format!("/api/v1/targets/{id}/devices")).await?,
|
|
)
|
|
.await
|
|
}
|
|
|
|
/// What Siemens' advisories know of `order_number`, as typed.
|
|
#[server]
|
|
pub async fn lookup_device(order_number: String) -> Result<DeviceLookup, ServerFnError> {
|
|
super::agent_client::data(
|
|
super::agent_client::agent_get("/api/v1/devices/lookup")
|
|
.await?
|
|
.query(&[("order_number", order_number)]),
|
|
)
|
|
.await
|
|
}
|
|
|
|
/// Store `devices` as target `id`'s devices, replacing the ones it had.
|
|
#[server]
|
|
pub async fn save_devices(id: String, devices: Vec<PlcDevice>) -> Result<(), ServerFnError> {
|
|
let resp = super::agent_client::agent_request(
|
|
reqwest::Method::PATCH,
|
|
&format!("/api/v1/targets/{id}"),
|
|
)
|
|
.await?
|
|
.json(&serde_json::json!({ "devices": devices }))
|
|
.send()
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
super::agent_client::ok_or_error(resp).await
|
|
}
|