use std::collections::HashMap;
use async_trait::async_trait;
use firkin_e2b_contract::BackendError as E2bBackendError;
use firkin_envd::{
EnvdProcessEventStream, EnvdProcessInfo, EnvdProcessInput, EnvdProcessOutput,
EnvdProcessSelector, EnvdProcessSignal, EnvdProcessStartRequest, EnvdPtySize,
};
use super::{
CommandOutput, CommandRequest, Error, Result, RuntimeCreatedSandbox, RuntimeSnapshotRef,
SingleNodeCreateRequest, SnapshotRecord,
};
#[async_trait]
pub trait RuntimeDriver: Send + Sync {
fn runtime_sandbox_exists(&self, sandbox_id: &str) -> Result<bool>;
async fn create(&self, request: SingleNodeCreateRequest) -> Result<RuntimeCreatedSandbox>;
async fn delete(&self, sandbox_id: &str) -> Result<()>;
async fn restore(
&self,
request: SingleNodeCreateRequest,
_snapshot: SnapshotRecord,
) -> Result<RuntimeCreatedSandbox> {
self.create(request).await
}
async fn snapshot(
&self,
_sandbox_id: &str,
_name: Option<String>,
) -> Result<RuntimeSnapshotRef> {
Err(Error::UnsupportedCapability(
"single-node runtime snapshot is not implemented by this driver".to_string(),
))
}
async fn delete_snapshot(&self, _snapshot_id: &str) -> Result<()> {
Ok(())
}
async fn run_command(
&self,
_sandbox_id: &str,
_request: CommandRequest,
) -> Result<CommandOutput> {
Err(Error::UnsupportedCapability(
"single-node runtime command execution is not implemented by this driver".to_string(),
))
}
async fn start_process_stream(
&self,
_sandbox_id: &str,
_request: EnvdProcessStartRequest,
) -> Result<EnvdProcessEventStream<E2bBackendError>> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process streaming is not implemented by this driver"
.to_string(),
))
}
async fn list_processes(&self, _sandbox_id: &str) -> Result<Vec<EnvdProcessInfo>> {
Ok(Vec::new())
}
async fn connect_process(
&self,
_sandbox_id: &str,
_selector: EnvdProcessSelector,
) -> Result<EnvdProcessOutput> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process connect is not implemented by this driver"
.to_string(),
))
}
async fn send_process_input(
&self,
_sandbox_id: &str,
_selector: EnvdProcessSelector,
_input: EnvdProcessInput,
) -> Result<()> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process input is not implemented by this driver"
.to_string(),
))
}
async fn close_process_stdin(
&self,
_sandbox_id: &str,
_selector: EnvdProcessSelector,
) -> Result<()> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process stdin close is not implemented by this driver"
.to_string(),
))
}
async fn signal_process(
&self,
_sandbox_id: &str,
_selector: EnvdProcessSelector,
_signal: EnvdProcessSignal,
) -> Result<()> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process signal is not implemented by this driver"
.to_string(),
))
}
async fn resize_process_pty(
&self,
_sandbox_id: &str,
_selector: EnvdProcessSelector,
_pty: Option<EnvdPtySize>,
) -> Result<()> {
Err(Error::UnsupportedCapability(
"single-node runtime retained process PTY resize is not implemented by this driver"
.to_string(),
))
}
async fn start_template_command(
&self,
_sandbox_id: &str,
_command: String,
_envs: HashMap<String, String>,
) -> Result<()> {
Err(Error::UnsupportedCapability(
"single-node runtime template start command is not implemented by this driver"
.to_string(),
))
}
}