pub struct Redactor { /* private fields */ }Expand description
Configurable redaction builder for secrets and legacy field names.
Redactor encapsulates redaction policy, custom secret field names, and
exact legacy URL 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 url_names<I: IntoIterator<Item = S>, S: Into<String>>(
self,
names: I,
) -> Self
pub fn url_names<I: IntoIterator<Item = S>, S: Into<String>>( self, names: I, ) -> Self
Set exact legacy field names whose values should receive URL-aware
redaction in addition to _url/_URL suffixed fields.
A matching string is handled like an _url value. Arrays and nested
collections recursively apply that treatment to every string leaf.
Matching is exact and does not normalize case, whitespace, or spelling.
Sourcepub fn reveal_names<I: IntoIterator<Item = S>, S: Into<String>>(
self,
names: I,
) -> Self
pub fn reveal_names<I: IntoIterator<Item = S>, S: Into<String>>( self, names: I, ) -> Self
Reveal exactly these structured field names at any depth. Other secrets remain masked; URL parameters and argv never use this exception.
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 value_at(&self, path: &[PathStep], value: &Value) -> Value
pub fn value_at(&self, path: &[PathStep], value: &Value) -> Value
Redact value as the node found at path inside a larger value: the
result is exactly what that node looks like in Redactor::value of
the whole.
Taking a node out of its document drops the names above it, and those
names are what redaction reads. So path carries them back: an object
key on it that is secret (by _secret suffix or secret_names, and not
in reveal_names) masks the node whole — to ***, except that a node
which is itself the secret field and is null stays null, as it does
in the whole. A key on it that is a URL field (_url suffix or
url_names) scrubs credentials from every string the node holds. The
policy scopes the same way too: under RedactionPolicy::TraceOnly
only a path into the top-level trace object is redacted.
path is the structural route — PathStep::Field for each object key,
PathStep::Element for each array element — as
document::locate returns it. An
identifier that selected an element is not a key on the route, so it
never makes the element secret; the element’s own keys still do.
Sourcepub fn redact_in_place_at(&self, path: &[PathStep], value: &mut Value)
pub fn redact_in_place_at(&self, path: &[PathStep], value: &mut Value)
Redactor::value_at without the copy.
Sourcepub fn is_secret_path(&self, path: &[PathStep]) -> bool
pub fn is_secret_path(&self, path: &[PathStep]) -> bool
Whether the node at path is secret by name: some object key on the
route is secret and not revealed, within the policy’s scope. This is
the gate for a caller about to print the raw node rather than its
redacted form. A URL field on the route does not count: whether its
strings carry a credential is a question about the value, which
Redactor::value_at answers.
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. A
fragment written in the same k=v&k=v shape — how an OAuth implicit-flow
response carries its token — is redacted by that same rule; any other
fragment passes through byte-for-byte. 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.
A URL is unscoped input: RedactionPolicy::Off returns it unchanged,
every other policy redacts it in full.
Sourcepub fn urls_in_text(&self, text: &str) -> String
pub fn urls_in_text(&self, text: &str) -> String
Redact complete scheme-prefixed URLs embedded in prose.
This is deliberately explicit and independent from structured field redaction. It recognizes URL spans only; it never scans surrounding text for secret-looking names or values.
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.
A command line is unscoped input: RedactionPolicy::Off returns args
unchanged, every other policy redacts in full.
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.
This judges one name. A value taken out of a document is judged by its
whole route instead — a secret ancestor hides it as surely as a secret
leaf, and an identifier that selected an array element is not a name at
all — so use Redactor::is_secret_path and Redactor::value_at
there rather than testing the path’s last segment with this.
Sourcepub fn is_url_name(&self, name: &str) -> bool
pub fn is_url_name(&self, name: &str) -> bool
True when name receives URL-aware structured-field redaction: an
exact _url/_URL suffix or an exact configured url_names entry.
The counterpart to Redactor::is_secret_name, with the same caveat:
for a value taken out of a document, Redactor::value_at applies the
URL scrubbing its route calls for.
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 Forget for Redactor
impl Freeze for Redactor
impl Move for Redactor
impl RefUnwindSafe for Redactor
impl Send for Redactorwhere
RawVecInner: Send,
impl Sync for Redactorwhere
RawVecInner: Sync,
impl Unpin for Redactor
impl UnsafeUnpin for Redactor
impl UnwindSafe for Redactorwhere
RawVecInner: UnwindSafe,
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.