Skip to content

Commit 33938e7

Browse files
Return exit code 1 when secrets are found for CI pipeline usage
1 parent 9ae72fc commit 33938e7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ fn main() -> std::io::Result<()> {
2121
let rules = rules::load_rules(rules_file)?;
2222
info!("Loaded {} rules", rules.len());
2323

24-
scanner::scan_log(log_file, &rules)?;
24+
let findings = scanner::scan_log(log_file, &rules)?;
25+
26+
if findings > 0 {
27+
std::process::exit(1);
28+
}
2529

2630
Ok(())
2731
}

src/scanner.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct Match {
1616
}
1717

1818
/// Scans a log file using the provided rules and prints matches in a formatted table.
19-
pub fn scan_log<P: AsRef<std::path::Path>>(log_path: P, rules: &[Rule]) -> io::Result<()> {
19+
/// Returns the number of matches found.
20+
pub fn scan_log<P: AsRef<std::path::Path>>(log_path: P, rules: &[Rule]) -> io::Result<usize> {
2021
let file = File::open(log_path)?;
2122
let reader = BufReader::new(file);
2223

@@ -73,9 +74,10 @@ pub fn scan_log<P: AsRef<std::path::Path>>(log_path: P, rules: &[Rule]) -> io::R
7374
]));
7475
}
7576

77+
let count = table.row_count();
7678
println!("{table}");
7779

78-
Ok(())
80+
Ok(count)
7981
}
8082

8183
#[cfg(test)]

0 commit comments

Comments
 (0)