Skip to main content

rskit_process/command/
redaction.rs

1//! Redaction policy for command-line arguments emitted in spawn logs.
2
3use rskit_util::SecretKeyMatcher;
4
5/// Redaction policy for command-line arguments emitted in process spawn logs.
6#[derive(Debug, Clone, Eq, PartialEq, Default)]
7pub struct ArgRedaction {
8    matcher: SecretKeyMatcher,
9}
10
11impl ArgRedaction {
12    /// Create a policy with the default secret-bearing argument names.
13    #[must_use]
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    /// Replace the default secret-bearing names with the provided names.
19    #[must_use]
20    pub fn from_names(names: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
21        Self {
22            matcher: SecretKeyMatcher::new(names),
23        }
24    }
25
26    /// Add a secret-bearing argument name.
27    #[must_use]
28    pub fn with_name(mut self, name: impl AsRef<str>) -> Self {
29        self.matcher = self.matcher.with_name(name);
30        self
31    }
32
33    /// Add multiple secret-bearing argument names.
34    #[must_use]
35    pub fn with_names(mut self, names: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
36        self.matcher = self.matcher.with_names(names);
37        self
38    }
39
40    /// Return true when an argument name should have its value redacted.
41    #[must_use]
42    pub fn is_sensitive_arg_name(&self, name: &str) -> bool {
43        self.matcher.is_secret_key(name)
44    }
45}