Skip to main content

ApplicationValidator

Struct ApplicationValidator 

Source
pub struct ApplicationValidator { /* private fields */ }
Expand description

High-level builder for validating your application’s permission list.

ApplicationValidator collects permission strings from one or more sources, validates them for duplicates and hash collisions, and returns a ValidationReport.

This is the easiest API to use at startup or in tests when you want to say: “here is the full permission surface of my application; make sure it is safe.”

If you need reusable post-validation inspection helpers, use PermissionCollisionChecker directly.

§Examples

use webgates_core::permissions::application_validator::ApplicationValidator;///
let config_permissions = load_config_permissions();
let db_permissions = load_db_permissions().await?;

let report = ApplicationValidator::new()
    .add_permissions(config_permissions)
    .add_permissions(db_permissions)
    .add_permission("system:health")
    .validate()?;

assert!(report.is_valid());
use webgates_core::permissions::application_validator::ApplicationValidator;
use webgates_core::permissions::collision_checker::PermissionCollisionChecker;

let permissions = vec!["user:read".to_string(), "user:write".to_string()];

let report = ApplicationValidator::new()
    .add_permissions(permissions.clone())
    .validate()
    .map_err(|error| error.to_string())?;

let mut checker = PermissionCollisionChecker::new(permissions);
let inspected = checker.validate().map_err(|error| error.to_string())?;

assert_eq!(report.is_valid(), inspected.is_valid());

Implementations§

Source§

impl ApplicationValidator

Source

pub fn new() -> Self

Creates a new empty validator.

Source

pub fn add_permissions<I, S>(self, permissions: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Adds permissions from an iterator of string-like values.

§Arguments
  • permissions - Iterator of items that can be converted to String
Source

pub fn add_permission_strings(self, permissions: Vec<String>) -> Self

Adds permissions from a vector of owned strings.

This is a convenience method for callers that already have Vec<String>.

§Arguments
  • permissions - Vector of permission strings
Source

pub fn add_permission<S: Into<String>>(self, permission: S) -> Self

Adds one permission string.

§Arguments
  • permission - A single permission string to add
Source

pub fn validate(self) -> Result<ValidationReport, PermissionsError>

Validates all collected permissions and returns a detailed report.

This method performs validation and logs results automatically. It returns a ValidationReport whether validation succeeds or fails, unless the validation process itself encounters an unexpected error.

§Returns
  • Ok(ValidationReport) - Complete validation report
  • Err(webgates_core::errors::Error) - Validation process failed
Source

pub fn permission_count(&self) -> usize

Returns how many permission strings are currently queued for validation.

Trait Implementations§

Source§

impl Default for ApplicationValidator

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more