Skip to main content

approve_if

Function approve_if 

Source
pub fn approve_if<F>(
    inner: Arc<dyn SessionHandler>,
    predicate: F,
) -> Arc<dyn SessionHandler>
where F: Fn(&PermissionRequestData) -> bool + Send + Sync + 'static,
Expand description

Wrap inner with a closure-based policy: predicate is called for each permission request; true approves, false denies. All other events are forwarded to inner.

let inner = Arc::new(ApproveAllHandler);
let handler = permission::approve_if(inner, |data| {
    // Inspect data.extra (the raw JSON payload) for custom policy.
    data.extra.get("tool").and_then(|v| v.as_str()) != Some("shell")
});