#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Action {
Warn,
Redact,
Block,
}
use std::borrow::Cow;
#[derive(Debug, Clone)]
pub enum ViolationSource {
BuiltIn(crate::pattern::PatternId),
Custom(String),
}
#[derive(Debug, Clone)]
pub struct Violation {
pub source: ViolationSource,
pub description: Cow<'static, str>,
pub action: Action,
pub matched: String,
}
#[derive(Debug, Clone)]
pub struct InspectionResult {
pub violations: Vec<Violation>,
pub blocked: bool,
pub content: String,
}
impl InspectionResult {
pub fn is_clean(&self) -> bool {
self.violations.is_empty()
}
}
pub const REDACTED_PLACEHOLDER: &str = "[REDACTED]";
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn inspection_result_is_clean_when_empty() {
let result = InspectionResult {
violations: vec![],
blocked: false,
content: "hello world".to_owned(),
};
assert!(result.is_clean());
}
#[test]
fn inspection_result_is_not_clean_with_violations() {
let result = InspectionResult {
violations: vec![Violation {
source: ViolationSource::BuiltIn(crate::pattern::PatternId::ApiKeys),
description: Cow::Borrowed("API keys from common providers"),
action: Action::Warn,
matched: "sk-abc123".to_owned(),
}],
blocked: false,
content: "hello sk-abc123".to_owned(),
};
assert!(!result.is_clean());
}
}