summaryrefslogtreecommitdiffstats
path: root/src/sandbox/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sandbox/mod.rs')
-rw-r--r--src/sandbox/mod.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs
index b20788d..cdbfa02 100644
--- a/src/sandbox/mod.rs
+++ b/src/sandbox/mod.rs
@@ -29,6 +29,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
+use crate::config::Config;
use crate::error::Result;
pub mod agent;
@@ -138,3 +139,27 @@ pub trait SandboxBackend: Send + Sync {
fn acquire(&self, spec: &SandboxSpec) -> Result<Arc<dyn Sandbox>>;
fn status(&self) -> Result<Vec<SandboxInfo>>;
}
+
+/// Turn a configuration into the backend it names — the only place that does,
+/// so "which backend" has exactly one answer.
+///
+/// `Config::validate` runs here as well as at startup: a guard that only exists
+/// in the CLI is a guard a test, a tool, or a future daemon can walk past.
+/// And an unknown or unwired kind is an error, never a fallthrough — a build
+/// configured for a Kata VM that quietly ran as the hub's own user is the
+/// failure this function used to have.
+pub fn backend_for(cfg: &Config) -> Result<Arc<dyn SandboxBackend>> {
+ cfg.validate()?;
+ match &cfg.sandbox {
+ crate::config::Sandbox::Loopback => {
+ Ok(Arc::new(loopback::LoopbackBackend::new(cfg)))
+ }
+ crate::config::Sandbox::Remote { listen, token, .. } => {
+ Ok(Arc::new(remote::RemoteBackend::bind(cfg, listen, token)?))
+ }
+ crate::config::Sandbox::AgentSandbox { .. } => Err(crate::error::Error::invalid(concat!(
+ "sandbox kind \"agent-sandbox\" is not wired up yet; refusing to run this build ",
+ "on a backend it was not configured for",
+ ))),
+ }
+}