From 6e3c42a14dade6f6973c6db009053dec868d5b1c Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Sun, 12 Jul 2026 22:15:21 +0200 Subject: [PATCH] wip(wizard): onboarding server fns (infrastructure/onboarding.rs) --- .../src/infrastructure/onboarding.rs | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 compliance-dashboard/src/infrastructure/onboarding.rs diff --git a/compliance-dashboard/src/infrastructure/onboarding.rs b/compliance-dashboard/src/infrastructure/onboarding.rs new file mode 100644 index 0000000..3939000 --- /dev/null +++ b/compliance-dashboard/src/infrastructure/onboarding.rs @@ -0,0 +1,105 @@ +//! 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())) +}