use crate::types::action::Action;
#[derive(Debug, Clone)]
pub enum GuardResult {
Allow,
Deny {
reason: String,
severity: GuardSeverity,
},
Sanitize {
modified_action: Action,
warning: String,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GuardSeverity {
Critical,
High,
Medium,
}
pub trait Guard: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn check(&self, action: &Action) -> GuardResult;
}
pub struct NoopGuard;
impl Guard for NoopGuard {
fn name(&self) -> &'static str {
"noop"
}
fn check(&self, _action: &Action) -> GuardResult {
GuardResult::Allow
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_noop_guard_allows_everything() {
let guard = NoopGuard;
let action = Action::RawOutput {
content: "test".into(),
};
assert!(matches!(guard.check(&action), GuardResult::Allow));
}
}