pub struct Redactor { /* private fields */ }Expand description
Configurable redaction builder for secrets and legacy field names.
Redactor encapsulates redaction policy and custom secret field names.
Build with Redactor::new(), configure via builder methods, then pass to
redaction functions like redacted_value or redact_url_secrets.
Implementations§
Source§impl Redactor
impl Redactor
Sourcepub fn secret_names<I: IntoIterator<Item = S>, S: Into<String>>(
self,
names: I,
) -> Self
pub fn secret_names<I: IntoIterator<Item = S>, S: Into<String>>( self, names: I, ) -> Self
Set custom field names to treat as secrets in addition to _secret suffixes.
Matching is exact field-name equality at any nesting level. The same
list also matches URL query-parameter names inside _url fields.
Builder style: returns self.
Sourcepub fn policy(self, policy: RedactionPolicy) -> Self
pub fn policy(self, policy: RedactionPolicy) -> Self
Set the redaction policy (default: full redaction).
Builder style: returns self.
Sourcepub fn value(&self, value: &Value) -> Value
pub fn value(&self, value: &Value) -> Value
Redact a JSON value copy using this redactor’s policy and secret names.
Clones value first; for a large payload you already own and can
mutate, prefer Redactor::redact_in_place to avoid the copy.
Sourcepub fn url(&self, url: &str) -> String
pub fn url(&self, url: &str) -> String
Redact secret components of a URL string using this redactor’s settings.
A query parameter is redacted iff its (form-decoded) name ends in
_secret/_SECRET or matches an exact entry in secret_names. The
userinfo password (scheme://user:pass@host) is always redacted as a
structural rule. Only the secret spans are replaced with ***; every
other byte is preserved. A string that is not a single, whitespace-free,
scheme-prefixed URL (including a URL embedded in surrounding prose) is
returned unchanged.
Sourcepub fn redact_in_place(&self, value: &mut Value)
pub fn redact_in_place(&self, value: &mut Value)
Redact value in place, using this redactor’s policy and secret names.
The zero-copy counterpart of Redactor::value — use it on a large
payload you already own to avoid cloning.
Sourcepub fn argv<S: AsRef<str>>(&self, args: &[S]) -> Vec<String>
pub fn argv<S: AsRef<str>>(&self, args: &[S]) -> Vec<String>
Redact secret values out of a command line, using this redactor’s policy and secret names.
A long flag whose name is secret by AFDATA naming (--api-key-secret,
or an exact secret_names entry) has its value replaced by ***, in
both --flag=value and --flag value spellings. Everything else is
preserved byte-for-byte.
Free text is deliberately never scanned: a bare api_key_secret=sk-live
positional, or a secret-looking token after a non-secret flag, is left
alone. AFDATA decides sensitivity from the field name, and argv is no
exception — rename the flag rather than pattern-matching values. A flag
with no value (end of argv, or followed by another flag) is likewise
left inspectable.
Only long (--) flags are recognized, matching the convention’s
long-flags-only rule.
Sourcepub fn is_secret_name(&self, name: &str) -> bool
pub fn is_secret_name(&self, name: &str) -> bool
True when name would be treated as a secret field name by this
redactor: an exact _secret/_SECRET suffix, or an exact match
against a configured secret_names entry.
Exposed for callers that must gate on a single targeted field name
(for example a CLI dot-path leaf) rather than redact a whole value —
Redactor::value only rewrites fields it finds while walking an
object, so a bare scalar pulled out from under its field name needs
this explicit check instead.
Trait Implementations§
impl Eq for Redactor
Source§impl From<RedactionPolicy> for Redactor
impl From<RedactionPolicy> for Redactor
Source§fn from(policy: RedactionPolicy) -> Self
fn from(policy: RedactionPolicy) -> Self
impl StructuralPartialEq for Redactor
Auto Trait Implementations§
impl Freeze for Redactor
impl RefUnwindSafe for Redactor
impl Send for Redactor
impl Sync for Redactor
impl Unpin for Redactor
impl UnsafeUnpin for Redactor
impl UnwindSafe for Redactor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.