pub struct PolicyEnforcer { /* private fields */ }Expand description
Deterministic policy evaluator. Constructed once from config, immutable thereafter.
Implementations§
Source§impl PolicyEnforcer
impl PolicyEnforcer
Sourcepub fn compile(config: &PolicyConfig) -> Result<Self, PolicyCompileError>
pub fn compile(config: &PolicyConfig) -> Result<Self, PolicyCompileError>
Compile a PolicyConfig into a PolicyEnforcer.
§Errors
Returns PolicyCompileError if any glob or regex in the config is invalid,
or if the policy file cannot be loaded or parsed.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Return the total number of compiled rules (inline + file-loaded).
Sourcepub fn evaluate(
&self,
tool_name: &str,
params: &Map<String, Value>,
context: &PolicyContext,
) -> PolicyDecision
pub fn evaluate( &self, tool_name: &str, params: &Map<String, Value>, context: &PolicyContext, ) -> PolicyDecision
Evaluate a tool call against the compiled policy rules.
Returns PolicyDecision::Deny when any deny rule matches.
Returns PolicyDecision::Allow when any allow/allow_if rule matches.
Falls back to default_effect when no rule matches.
Tool name is normalized (lowercase, trimmed) before matching.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PolicyEnforcer
impl RefUnwindSafe for PolicyEnforcer
impl Send for PolicyEnforcer
impl Sync for PolicyEnforcer
impl Unpin for PolicyEnforcer
impl UnsafeUnpin for PolicyEnforcer
impl UnwindSafe for PolicyEnforcer
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
Mutably borrows from an owned value. Read more