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: OOutcome granted when the condition succeeds.
label: Option<ClauseLabel>Optional trace label for this clause.
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.
Implementations§
Source§impl<O: Serialize> Policy<O>
impl<O: Serialize> Policy<O>
Sourcepub fn hash(&self) -> Result<PolicyHash, Error>
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>
impl<O> Policy<O>
Sourcepub fn try_labeled(self, label: impl Into<String>) -> GatekeepResult<Self>
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.
Marks grant denial as hidden.
Sourcepub fn reason(self, reason: impl IntoReasonCode) -> Self
pub fn reason(self, reason: impl IntoReasonCode) -> Self
Adds a reason code to grant denials.
Sourcepub fn try_reason(self, reason: impl Into<String>) -> GatekeepResult<Self>
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.
Sourcepub fn with_obligation<S: ObligationSpec>(self) -> Self
pub fn with_obligation<S: ObligationSpec>(self) -> Self
Adds a typed obligation to grant permits.