//! Server functions for the onboarding wizard — proxy to the agent's //! `/api/v1/targets` endpoints. use dioxus::prelude::*; use serde::{Deserialize, Serialize}; /// One artifact the wizard collects for a target. #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] pub struct ArtifactInputDto { pub kind: String, pub source_ref: String, #[serde(skip_serializing_if = "Option::is_none")] pub branch: Option, #[serde(skip_serializing_if = "Option::is_none")] pub plc_format: Option, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct TargetsResponse { pub data: Vec, pub total: Option, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct TargetResponse { pub data: serde_json::Value, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct ApplicableScansData { #[serde(default)] pub scans: Vec, #[serde(default)] pub pentest_supported: bool, } #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct ApplicableScansResponse { pub data: ApplicableScansData, } /// List onboarded targets. #[server] pub async fn fetch_targets() -> Result { let resp = super::agent_client::agent_get("/api/v1/targets") .await? .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; resp.json() .await .map_err(|e| ServerFnError::new(e.to_string())) } /// Create a target with the collected artifacts. #[server] pub async fn create_target( name: String, target_type: String, description: Option, artifacts: Vec, ) -> Result { let body = serde_json::json!({ "name": name, "target_type": target_type, "description": description, "artifacts": artifacts, }); let resp = super::agent_client::agent_request(reqwest::Method::POST, "/api/v1/targets") .await? .json(&body) .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; resp.json() .await .map_err(|e| ServerFnError::new(e.to_string())) } /// Run kind-based classification on a target. #[server] pub async fn detect_target(id: String) -> Result { let resp = super::agent_client::agent_request( reqwest::Method::POST, &format!("/api/v1/targets/{id}/detect"), ) .await? .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; resp.json() .await .map_err(|e| ServerFnError::new(e.to_string())) } /// Fetch the scan-applicability matrix for a target. #[server] pub async fn fetch_applicable_scans(id: String) -> Result { let resp = super::agent_client::agent_get(&format!("/api/v1/targets/{id}/applicable-scans")) .await? .send() .await .map_err(|e| ServerFnError::new(e.to_string()))?; resp.json() .await .map_err(|e| ServerFnError::new(e.to_string())) }