pub fn validate_detector(spec: &DetectorSpec) -> Vec<QualityIssue>Expand description
Validate a detector spec against the quality gate.
ยงExamples
use keyhog_core::{DetectorSpec, PatternSpec, Severity, validate_detector};
let detector = DetectorSpec {
id: "demo".into(),
name: "Demo".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
};
assert!(validate_detector(&detector).is_empty());Examples found in repository?
examples/core_standalone.rs (line 23)
7fn main() {
8 let detector = DetectorSpec {
9 id: "demo-token".into(),
10 name: "Demo Token".into(),
11 service: "demo".into(),
12 severity: Severity::High,
13 patterns: vec![PatternSpec {
14 regex: "demo_[A-Z0-9]{8}".into(),
15 description: Some("Simple standalone example".into()),
16 group: None,
17 }],
18 companion: None,
19 verify: None,
20 keywords: vec!["demo_".into()],
21 };
22
23 let issues = validate_detector(&detector);
24 let allowlist = Allowlist::parse("path:**/*.md\n");
25 let maybe_detectors = load_detectors_with_gate(Path::new("detectors"), true).ok();
26
27 println!("detector={} issues={}", detector.id, issues.len());
28 println!("redacted={}", redact("demo_ABC12345"));
29 println!(
30 "ignores_docs={}",
31 allowlist.is_path_ignored("docs/README.md")
32 );
33 println!(
34 "workspace_detectors_loaded={}",
35 maybe_detectors.as_ref().map_or(0, Vec::len)
36 );
37}