pub enum CommandCheckResult {
Allowed,
Denied(String),
RequiresApproval {
request: ApprovalRequest,
grant_pattern: String,
},
}Expand description
Result of a command permission check.
Unlike can_execute_command which returns a simple bool, this enum
provides more granular control:
Allowed: Command can execute immediatelyDenied: Command is permanently blockedRequiresApproval: Command needs HIL approval before execution
§HIL Integration
When RequiresApproval is returned, the caller should:
- Submit the
ApprovalRequesttoHilComponent - Wait for user approval/rejection
- If approved, call
grants.grant(CommandGrant::persistent(grant_pattern)) - Retry the command (which will now return
Allowed)
§Example
ⓘ
match checker.check_command(&session, "rm -rf ./temp") {
CommandCheckResult::Allowed => execute(cmd),
CommandCheckResult::Denied(reason) => error!("{}", reason),
CommandCheckResult::RequiresApproval { request, grant_pattern } => {
let id = hil.submit(request);
if await_approval(id) {
session.grant_command(&grant_pattern);
execute(cmd);
}
}
}Variants§
Allowed
Command is allowed to execute.
Denied(String)
Command is denied with a reason.
RequiresApproval
Command requires user approval via HIL.
Fields
§
request: ApprovalRequestThe approval request to submit to HilComponent.
Implementations§
Source§impl CommandCheckResult
impl CommandCheckResult
Sourcepub fn is_allowed(&self) -> bool
pub fn is_allowed(&self) -> bool
Returns true if the command is allowed.
Sourcepub fn requires_approval(&self) -> bool
pub fn requires_approval(&self) -> bool
Returns true if the command requires approval.
Sourcepub fn denial_reason(&self) -> Option<&str>
pub fn denial_reason(&self) -> Option<&str>
Returns the denial reason if denied.
Sourcepub fn approval_request(&self) -> Option<&ApprovalRequest>
pub fn approval_request(&self) -> Option<&ApprovalRequest>
Returns the approval request if requires approval.
Sourcepub fn grant_pattern(&self) -> Option<&str>
pub fn grant_pattern(&self) -> Option<&str>
Returns the grant pattern if requires approval.
Trait Implementations§
Source§impl Clone for CommandCheckResult
impl Clone for CommandCheckResult
Source§fn clone(&self) -> CommandCheckResult
fn clone(&self) -> CommandCheckResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CommandCheckResult
impl RefUnwindSafe for CommandCheckResult
impl Send for CommandCheckResult
impl Sync for CommandCheckResult
impl Unpin for CommandCheckResult
impl UnsafeUnpin for CommandCheckResult
impl UnwindSafe for CommandCheckResult
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