Skip to main content

Policy

Enum Policy 

Source
pub enum Policy<O> {
    Permit(O),
    Deny,
    Grant {
        outcome: O,
        condition: Condition,
        label: Option<ClauseLabel>,
        deny_shape: DenyShape,
        obligations: Vec<ObligationId>,
        reason: Option<ReasonCode>,
    },
    All(Vec<Self>),
    Any(Vec<Self>),
    OrElse {
        primary: Box<Self>,
        fallback: Box<Self>,
    },
}
Expand description

Reified authorization policy.

Variants§

§

Permit(O)

Unconditional permit with an outcome.

§

Deny

Unconditional denial.

§

Grant

Conditional permit with denial metadata.

Fields

§outcome: O

Outcome granted when the condition succeeds.

§condition: Condition

Predicate that guards the grant.

§label: Option<ClauseLabel>

Optional trace label for this clause.

§deny_shape: DenyShape

Shape exposed when the grant condition fails.

§obligations: Vec<ObligationId>

Obligations attached to a successful grant.

§reason: Option<ReasonCode>

Reason code attached to a failed grant.

§

All(Vec<Self>)

Meet composition across child policies.

§

Any(Vec<Self>)

Join composition across child policies.

§

OrElse

Fallback policy used only when the primary denies.

Fields

§primary: Box<Self>

Primary policy.

§fallback: Box<Self>

Fallback policy.

Implementations§

Source§

impl<O: Serialize> Policy<O>

Source

pub fn hash(&self) -> Result<PolicyHash, Error>

Computes a stable hash of the serialized policy value.

§Errors

Returns a postcard::Error when the policy cannot be serialized.

Source§

impl<O> Policy<O>

Source

pub fn labeled(self, label: impl IntoLabel) -> Self

Adds a label to grant policies.

Source

pub fn try_labeled(self, label: impl Into<String>) -> GatekeepResult<Self>

Tries to add a validated label to grant policies.

§Errors

Returns crate::GatekeepError::EmptyIdentifier when label is empty or contains only whitespace.

Source

pub const fn hidden(self) -> Self

Marks grant denial as hidden.

Source

pub fn reason(self, reason: impl IntoReasonCode) -> Self

Adds a reason code to grant denials.

Source

pub fn try_reason(self, reason: impl Into<String>) -> GatekeepResult<Self>

Tries to add a validated reason code to grant denials.

§Errors

Returns crate::GatekeepError::EmptyIdentifier when reason is empty or contains only whitespace.

Source

pub fn with_obligation<S: ObligationSpec>(self) -> Self

Adds a typed obligation to grant permits.

Trait Implementations§

Source§

impl<O: Clone> Clone for Policy<O>

Source§

fn clone(&self) -> Policy<O>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<O: Debug> Debug for Policy<O>

Source§

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

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

impl<'de, O> Deserialize<'de> for Policy<O>
where O: Deserialize<'de>,

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<O: Eq> Eq for Policy<O>

Source§

impl<O> From<GrantPolicy<O>> for Policy<O>

Source§

fn from(grant: GrantPolicy<O>) -> Self

Converts to this type from the input type.
Source§

impl<O: PartialEq> PartialEq for Policy<O>

Source§

fn eq(&self, other: &Policy<O>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<O> Serialize for Policy<O>
where O: Serialize,

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

impl<O: PartialEq> StructuralPartialEq for Policy<O>

Auto Trait Implementations§

§

impl<O> Freeze for Policy<O>
where O: Freeze,

§

impl<O> RefUnwindSafe for Policy<O>
where O: RefUnwindSafe,

§

impl<O> Send for Policy<O>
where O: Send,

§

impl<O> Sync for Policy<O>
where O: Sync,

§

impl<O> Unpin for Policy<O>
where O: Unpin,

§

impl<O> UnsafeUnpin for Policy<O>
where O: UnsafeUnpin,

§

impl<O> UnwindSafe for Policy<O>
where O: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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.