Skip to main content

nxd_core/progress/
redaction.rs

1use nxd_plugin_protocol::SensitiveTextRedactor;
2
3#[derive(Clone, Debug, Default)]
4pub struct ProgressRedactor {
5	semantic: SensitiveTextRedactor,
6}
7
8impl ProgressRedactor {
9	pub fn with_sensitive_values<'a>(values: impl IntoIterator<Item = &'a [u8]>) -> Self {
10		Self { semantic: SensitiveTextRedactor::with_sensitive_values(values) }
11	}
12
13	pub fn redact(&mut self, input: &str) -> String {
14		self.semantic.redact(input)
15	}
16}
17
18pub fn redact_sensitive_text(input: &str) -> String {
19	ProgressRedactor::default().redact(input)
20}
21
22#[cfg(test)]
23mod tests {
24	use super::*;
25
26	#[test]
27	fn combines_exact_action_secret_and_semantic_redaction() {
28		let mut redactor = ProgressRedactor::with_sensitive_values([b"opaque-value".as_slice()]);
29		let rendered = redactor
30			.redact("ordinary build output opaque-value\ntoken=field-value\nsetting up secrets...");
31		assert_eq!(
32			rendered,
33			"ordinary build output [REDACTED]\ntoken=[REDACTED]\nsetting up secrets..."
34		);
35	}
36}