Skip to main content

FileTypeProfile

Struct FileTypeProfile 

Source
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:

  1. Its name ends with one of the extensions (required — an empty list matches nothing).
  2. If include is non-empty, the filename matches at least one of those glob patterns.
  3. The filename does not match any exclude glob 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: String

Name 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

Source

pub fn new(processor: impl Into<String>, fields: Vec<FieldRule>) -> Self

Create a minimal profile for a given processor.

Source

pub fn with_extension(self, ext: impl Into<String>) -> Self

Add an extension to this profile.

Source

pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add a free-form option.

Source

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:

  1. The filename ends with one of extensions (an empty list → false).
  2. If include is non-empty, the filename matches at least one glob.
  3. The filename does not match any exclude glob.

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"));
Source

pub fn with_include(self, pat: impl Into<String>) -> Self

Add a glob pattern to the include list.

Source

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

Source§

fn clone(&self) -> FileTypeProfile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileTypeProfile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for FileTypeProfile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for FileTypeProfile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,