agentshield/output/
mod.rs1pub mod console;
2pub mod html;
3pub mod json;
4pub mod sarif;
5
6use serde::{Deserialize, Serialize};
7
8use crate::error::Result;
9use crate::rules::policy::PolicyVerdict;
10use crate::rules::Finding;
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
14#[serde(rename_all = "lowercase")]
15pub enum OutputFormat {
16 Console,
17 Json,
18 Sarif,
19 Html,
20}
21
22impl OutputFormat {
23 pub fn from_str_lenient(s: &str) -> Option<Self> {
24 match s.to_lowercase().as_str() {
25 "console" | "text" => Some(Self::Console),
26 "json" => Some(Self::Json),
27 "sarif" => Some(Self::Sarif),
28 "html" => Some(Self::Html),
29 _ => None,
30 }
31 }
32}
33
34pub fn render(
36 findings: &[Finding],
37 verdict: &PolicyVerdict,
38 format: OutputFormat,
39 target_name: &str,
40) -> Result<String> {
41 match format {
42 OutputFormat::Console => Ok(console::render(findings, verdict)),
43 OutputFormat::Json => json::render(findings, verdict),
44 OutputFormat::Sarif => sarif::render(findings, target_name),
45 OutputFormat::Html => html::render(findings, verdict, target_name),
46 }
47}