pub struct FileTypeProfile {
pub processor: String,
pub extensions: Vec<String>,
pub include: Vec<String>,
pub exclude: Vec<String>,
pub fields: Vec<FieldRule>,
pub options: HashMap<String, String>,
}Expand description
Specifies which processor to use and what fields to sanitize.
§File matching
A file is processed by this profile when all of the following hold:
- Its name ends with one of the
extensions(required — an empty list matches nothing). - If
includeis non-empty, the filename matches at least one of those glob patterns. - The filename does not match any
excludeglob pattern.
Glob patterns use * (any chars within a path component) and **
(any chars including path separators).
§Example (YAML)
- processor: json
extensions: [".json"]
# Only apply to files whose names start with "config"
include: ["config*.json"]
# Never apply to log files
exclude: ["*.log.json", "logs/**"]
fields:
- pattern: "*.password"
category: "custom:password"Fields§
§processor: StringName of the processor to use (e.g. "key_value", "json").
extensions: Vec<String>File extensions this profile applies to (e.g. [".rb", ".conf"]).
include: Vec<String>If non-empty, the filename must match at least one of these glob patterns in addition to the extension check.
exclude: Vec<String>Filenames matching any of these glob patterns are excluded from structured processing even if they match the extension (and include).
fields: Vec<FieldRule>Field rules: which keys/paths to sanitize.
options: HashMap<String, String>Free-form options passed to the processor (e.g. delimiter, comment chars).
Implementations§
Source§impl FileTypeProfile
impl FileTypeProfile
Sourcepub fn new(processor: impl Into<String>, fields: Vec<FieldRule>) -> Self
pub fn new(processor: impl Into<String>, fields: Vec<FieldRule>) -> Self
Create a minimal profile for a given processor.
Sourcepub fn with_extension(self, ext: impl Into<String>) -> Self
pub fn with_extension(self, ext: impl Into<String>) -> Self
Add an extension to this profile.
Sourcepub fn with_option(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a free-form option.
Sourcepub fn matches_filename(&self, filename: &str) -> bool
pub fn matches_filename(&self, filename: &str) -> bool
Check whether a filename should be processed by this profile.
Returns true when all three conditions hold:
- The filename ends with one of
extensions(an empty list →false). - If
includeis non-empty, the filename matches at least one glob. - The filename does not match any
excludeglob.
Invalid glob patterns in include/exclude are silently skipped.
§Examples
use sanitize_engine::processor::profile::FieldRule;
use sanitize_engine::processor::profile::FileTypeProfile;
let profile = FileTypeProfile::new("json", vec![])
.with_extension(".json");
assert!(profile.matches_filename("config.json"));
assert!(profile.matches_filename("logs/app.json"));
assert!(!profile.matches_filename("config.yml"));
// Exclude log-formatted JSON files.
let profile = FileTypeProfile::new("json", vec![])
.with_extension(".json")
.with_exclude("*.log.json")
.with_exclude("logs/**");
assert!(profile.matches_filename("config.json"));
assert!(!profile.matches_filename("app.log.json"));
assert!(!profile.matches_filename("logs/events.json"));
// Include only config files.
let profile = FileTypeProfile::new("json", vec![])
.with_extension(".json")
.with_include("config*.json");
assert!(profile.matches_filename("config.json"));
assert!(profile.matches_filename("config-prod.json"));
assert!(!profile.matches_filename("events.json"));Sourcepub fn with_include(self, pat: impl Into<String>) -> Self
pub fn with_include(self, pat: impl Into<String>) -> Self
Add a glob pattern to the include list.
Sourcepub fn with_exclude(self, pat: impl Into<String>) -> Self
pub fn with_exclude(self, pat: impl Into<String>) -> Self
Add a glob pattern to the exclude list.
Trait Implementations§
Source§impl Clone for FileTypeProfile
impl Clone for FileTypeProfile
Source§fn clone(&self) -> FileTypeProfile
fn clone(&self) -> FileTypeProfile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FileTypeProfile
impl Debug for FileTypeProfile
Source§impl<'de> Deserialize<'de> for FileTypeProfile
impl<'de> Deserialize<'de> for FileTypeProfile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for FileTypeProfile
impl RefUnwindSafe for FileTypeProfile
impl Send for FileTypeProfile
impl Sync for FileTypeProfile
impl Unpin for FileTypeProfile
impl UnsafeUnpin for FileTypeProfile
impl UnwindSafe for FileTypeProfile
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more