pub struct Redaction { /* private fields */ }Expand description
Mask string and number leaves whose key matches a pattern.
A leaf’s key is the last key on its path, so the items of a tokens
list are masked too. Everything under a matching key is masked, so
{"password": {"value": "…"}} and an XML <password type="…">…</password>
(whose text sits under #text) are covered. Patterns match
case-insensitively, with - and _ interchangeable (api-key matches
api_key): as a substring, or as a whole-key glob when they contain *
or ?. Masked leaves become the mask string and keep their metadata;
booleans and nulls are left alone, and so is the structure.
use rich_ext::data::{parse, Format, Redaction, Value};
let node = parse(Format::Json, r#"{"db": {"user": "u", "Password": "hunter2"}}"#).unwrap();
let safe = node.redacted(&Redaction::secrets());
assert_eq!(safe.get("db").unwrap().get("Password").unwrap().value, Value::String("********".into()));
assert_eq!(safe.get("db").unwrap().get("user").unwrap().value, Value::String("u".into()));Implementations§
Source§impl Redaction
impl Redaction
Sourcepub fn secrets() -> Self
pub fn secrets() -> Self
Common secret key names (see SECRET_KEYS).
Sourcepub fn patterns<S: Into<String>>(
self,
patterns: impl IntoIterator<Item = S>,
) -> Self
pub fn patterns<S: Into<String>>( self, patterns: impl IntoIterator<Item = S>, ) -> Self
Add key patterns.
Sourcepub fn matches_key(&self, key: &str) -> bool
pub fn matches_key(&self, key: &str) -> bool
Whether key matches a pattern. - and _ are interchangeable.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Redaction
impl RefUnwindSafe for Redaction
impl Send for Redaction
impl Sync for Redaction
impl Unpin for Redaction
impl UnsafeUnpin for Redaction
impl UnwindSafe for Redaction
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
Mutably borrows from an owned value. Read more