use crate::{ConfigOverride, FeatureToggles};
use std::{ffi::OsString, path::PathBuf, process::ExitStatus};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SandboxPlatform {
Macos,
Linux,
Windows,
}
impl SandboxPlatform {
pub(crate) fn subcommand(self) -> &'static str {
match self {
SandboxPlatform::Macos => "macos",
SandboxPlatform::Linux => "linux",
SandboxPlatform::Windows => "windows",
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SandboxCommandRequest {
pub platform: SandboxPlatform,
pub command: Vec<OsString>,
pub full_auto: bool,
pub log_denials: bool,
pub allow_unix_socket: bool,
pub config_overrides: Vec<ConfigOverride>,
pub feature_toggles: FeatureToggles,
pub working_dir: Option<PathBuf>,
}
impl SandboxCommandRequest {
pub fn new<I, S>(platform: SandboxPlatform, command: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<OsString>,
{
Self {
platform,
command: command.into_iter().map(Into::into).collect(),
full_auto: false,
log_denials: false,
allow_unix_socket: false,
config_overrides: Vec::new(),
feature_toggles: FeatureToggles::default(),
working_dir: None,
}
}
pub fn full_auto(mut self, enable: bool) -> Self {
self.full_auto = enable;
self
}
pub fn log_denials(mut self, enable: bool) -> Self {
self.log_denials = enable;
self
}
pub fn allow_unix_socket(mut self, enable: bool) -> Self {
self.allow_unix_socket = enable;
self
}
pub fn config_override(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.config_overrides.push(ConfigOverride::new(key, value));
self
}
pub fn config_override_raw(mut self, raw: impl Into<String>) -> Self {
self.config_overrides.push(ConfigOverride::from_raw(raw));
self
}
pub fn enable_feature(mut self, name: impl Into<String>) -> Self {
self.feature_toggles.enable.push(name.into());
self
}
pub fn disable_feature(mut self, name: impl Into<String>) -> Self {
self.feature_toggles.disable.push(name.into());
self
}
pub fn working_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.working_dir = Some(dir.into());
self
}
}
#[derive(Clone, Debug)]
pub struct SandboxRun {
pub status: ExitStatus,
pub stdout: String,
pub stderr: String,
}