use std::{sync::Arc, time::Duration};
use futures::future::BoxFuture;
#[cfg(feature = "local")]
use super::LocalBackend;
use super::{
BackendInfo, BackendKind, BackendSelectionSource, SandboxBackend, SnapshotBackend,
VolumeBackend,
};
use crate::{
MicrosandboxResult,
error::{Operation, UnsupportedReason},
};
pub trait Backend: Send + Sync + 'static {
fn kind(&self) -> BackendKind;
fn info(&self) -> BackendInfo {
BackendInfo {
kind: self.kind(),
api_url: None,
source: BackendSelectionSource::Programmatic,
profile: None,
}
}
fn sandboxes(&self) -> &dyn SandboxBackend;
fn volumes(&self) -> &dyn VolumeBackend;
fn snapshots(&self) -> &dyn SnapshotBackend;
#[cfg(feature = "local")]
fn as_local(&self) -> Option<&LocalBackend> {
None
}
#[doc(hidden)]
fn with_agent_identity(&self, _name: &str, _id: &str) -> Option<Arc<dyn Backend>> {
None
}
fn dial_agent<'a>(
&'a self,
_name: &'a str,
_timeout: Duration,
) -> BoxFuture<'a, MicrosandboxResult<crate::agent::AgentClient>> {
Box::pin(async {
Err(crate::MicrosandboxError::unsupported(
Operation::AgentConnect,
UnsupportedReason::NotAvailable(
"this backend does not provide agent connectivity".into(),
),
))
})
}
}