pub mod capture;
pub mod env;
pub mod filesystem;
pub mod in_process;
pub mod network;
pub mod process;
pub mod sandbox;
pub use capture::{capture, Captured};
pub use env::{EnvPlan, EnvScope, SubprocessEnv, SubprocessEnvMode};
pub use filesystem::{DirEntry, FileSystem, Metadata};
pub use network::{
domains_name_host, is_internal_address, names_loopback, HttpRequest, HttpResponse, HttpStream,
Network, Origin, DEFAULT_MAX_REDIRECTS,
};
pub use process::{
ExitStatus, OutputChunk, OutputStream, Process, ProcessHandle, ProcessSpec,
OUTPUT_GRACE_AFTER_EXIT,
};
pub use sandbox::{
default_deny_read, default_deny_read_in, Confined, ConfinementReport, EgressProxy, Enforcement,
NetworkMode, ReadScope, Sandbox, SandboxMode, SandboxPolicy, SandboxSettings,
};
#[derive(Clone)]
pub struct ExecProviders {
pub process: std::sync::Arc<dyn Process>,
pub filesystem: std::sync::Arc<dyn FileSystem>,
pub network: std::sync::Arc<dyn Network>,
pub sandbox: std::sync::Arc<dyn Sandbox>,
}
impl ExecProviders {
pub fn in_process() -> Self {
Self {
process: std::sync::Arc::new(in_process::ScriptedProcess::new()),
filesystem: std::sync::Arc::new(in_process::InMemoryFileSystem::new()),
network: std::sync::Arc::new(in_process::OfflineNetwork::new()),
sandbox: std::sync::Arc::new(in_process::NoSandbox),
}
}
pub fn with_network(mut self, n: std::sync::Arc<dyn Network>) -> Self {
self.network = n;
self
}
}
impl std::fmt::Debug for ExecProviders {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ExecProviders")
}
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum ExecError {
#[error("execution environment unavailable: {0}")]
Unavailable(String),
#[error("refused by policy: {0}")]
Denied(String),
#[error("{0}")]
Failed(String),
}
impl ExecError {
pub fn unavailable(m: impl std::fmt::Display) -> Self {
Self::Unavailable(m.to_string())
}
pub fn denied(m: impl std::fmt::Display) -> Self {
Self::Denied(m.to_string())
}
pub fn failed(m: impl std::fmt::Display) -> Self {
Self::Failed(m.to_string())
}
}
impl From<ExecError> for crate::error::ToolError {
fn from(e: ExecError) -> Self {
match e {
ExecError::Unavailable(_) => Self::exec(e.to_string()),
ExecError::Denied(m) => Self::Denied(m),
ExecError::Failed(m) => Self::exec(m),
}
}
}