use apcore_cli::security::sandbox::{ModuleExecutionError, Sandbox};
use serde_json::Value;
pub struct SandboxManager {
sandbox: Sandbox,
}
impl SandboxManager {
pub fn new(enabled: bool, timeout_ms: u64) -> Self {
Self {
sandbox: Sandbox::new(enabled, timeout_ms),
}
}
pub fn is_enabled(&self) -> bool {
self.sandbox.is_enabled()
}
pub async fn execute(
&self,
module_id: &str,
input_data: Value,
) -> Result<Value, ModuleExecutionError> {
self.sandbox.execute(module_id, input_data).await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sandbox_new_enabled() {
let mgr = SandboxManager::new(true, 5000);
assert!(mgr.is_enabled());
}
#[test]
fn test_sandbox_new_disabled() {
let mgr = SandboxManager::new(false, 5000);
assert!(!mgr.is_enabled());
}
}