pub struct CommandPolicy { /* private fields */ }Expand description
A PermissionPolicy that governs ShellPermissionRequests by checking
the executable name, working directory, and environment variables.
Denied executables and env keys are rejected immediately. Allowed
executables pass. Unknown executables either require approval or are
denied, depending on require_approval_for_unknown.
§Example
use agentkit_tools_core::CommandPolicy;
let policy = CommandPolicy::new()
.allow_executable("git")
.allow_executable("cargo")
.deny_executable("rm")
.deny_env_key("AWS_SECRET_ACCESS_KEY")
.allow_cwd("/workspace")
.require_approval_for_unknown(true);Implementations§
Source§impl CommandPolicy
impl CommandPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new command policy with no rules and approval required for unknown executables.
Sourcepub fn allow_executable(self, executable: impl Into<String>) -> Self
pub fn allow_executable(self, executable: impl Into<String>) -> Self
Adds an executable name to the allow-list.
Sourcepub fn deny_executable(self, executable: impl Into<String>) -> Self
pub fn deny_executable(self, executable: impl Into<String>) -> Self
Adds an executable name to the deny-list.
Sourcepub fn allow_cwd(self, cwd: impl Into<PathBuf>) -> Self
pub fn allow_cwd(self, cwd: impl Into<PathBuf>) -> Self
Adds a directory root that commands are allowed to run in.
Sourcepub fn deny_env_key(self, key: impl Into<String>) -> Self
pub fn deny_env_key(self, key: impl Into<String>) -> Self
Adds an environment variable name to the deny-list.
Sourcepub fn require_approval_for_unknown(self, value: bool) -> Self
pub fn require_approval_for_unknown(self, value: bool) -> Self
When true (the default), executables not in the allow-list trigger
an approval request instead of an outright denial.
Trait Implementations§
Source§impl Default for CommandPolicy
impl Default for CommandPolicy
Source§impl PermissionPolicy for CommandPolicy
impl PermissionPolicy for CommandPolicy
Source§fn evaluate(&self, request: &dyn PermissionRequest) -> PolicyMatch
fn evaluate(&self, request: &dyn PermissionRequest) -> PolicyMatch
Evaluate the request and return a match or
PolicyMatch::NoOpinion.Auto Trait Implementations§
impl Freeze for CommandPolicy
impl RefUnwindSafe for CommandPolicy
impl Send for CommandPolicy
impl Sync for CommandPolicy
impl Unpin for CommandPolicy
impl UnsafeUnpin for CommandPolicy
impl UnwindSafe for CommandPolicy
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