use std::path::PathBuf;
use async_trait::async_trait;
use crate::error::CellosError;
use crate::types::{
CloudEventV1, ExecutionCellDocument, ExportArtifactMetadata, ExportReceipt,
ExportReceiptTargetKind, InferenceRequest, InferenceResponse, SecretView,
};
#[derive(Debug, Clone)]
pub struct CellHandle {
pub cell_id: String,
pub cgroup_path: Option<PathBuf>,
pub nft_rules_applied: Option<bool>,
pub kernel_digest_sha256: Option<String>,
pub rootfs_digest_sha256: Option<String>,
pub firecracker_digest_sha256: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct TeardownReport {
pub cell_id: String,
pub destroyed: bool,
pub peers_tracked_after: usize,
}
#[derive(Debug, Clone)]
pub struct RuntimeSecretLeaseRequest {
pub key: String,
pub ttl_seconds: u64,
}
#[async_trait]
pub trait CellBackend: Send + Sync {
async fn create(&self, spec: &ExecutionCellDocument) -> Result<CellHandle, CellosError>;
async fn destroy(&self, handle: &CellHandle) -> Result<TeardownReport, CellosError>;
async fn wait_for_in_vm_exit(&self, _cell_id: &str) -> Option<Result<i32, CellosError>> {
None
}
}
#[async_trait]
pub trait EventSink: Send + Sync {
async fn emit(&self, event: &CloudEventV1) -> Result<(), CellosError>;
}
#[async_trait]
pub trait SecretBroker: Send + Sync {
async fn resolve(
&self,
key: &str,
cell_id: &str,
ttl_seconds: u64,
) -> Result<SecretView, CellosError>;
async fn revoke_for_cell(&self, cell_id: &str) -> Result<(), CellosError>;
async fn prepare_runtime_secret_lease(
&self,
_cell_id: &str,
_requests: &[RuntimeSecretLeaseRequest],
) -> Result<(), CellosError> {
Err(CellosError::SecretBroker(
"runtimeLeasedBroker is not supported by this secret broker".into(),
))
}
async fn fetch_runtime_secret(
&self,
key: &str,
cell_id: &str,
ttl_seconds: u64,
) -> Result<SecretView, CellosError> {
self.resolve(key, cell_id, ttl_seconds).await
}
fn broker_correlation_id(&self) -> Option<String> {
None
}
}
#[async_trait]
pub trait ExportSink: Send + Sync {
fn target_kind(&self) -> Option<ExportReceiptTargetKind> {
None
}
fn destination_hint(&self, _name: &str) -> Option<String> {
None
}
async fn push(
&self,
name: &str,
path: &str,
metadata: &ExportArtifactMetadata,
) -> Result<ExportReceipt, CellosError>;
}
#[async_trait]
pub trait InferenceBroker: Send + Sync {
async fn infer(&self, request: &InferenceRequest) -> Result<InferenceResponse, CellosError>;
}
pub struct NoopInferenceBroker;
#[async_trait]
impl InferenceBroker for NoopInferenceBroker {
async fn infer(&self, _request: &InferenceRequest) -> Result<InferenceResponse, CellosError> {
Ok(InferenceResponse {
content: String::new(),
model: "noop".to_string(),
input_tokens: 0,
output_tokens: 0,
})
}
}
pub struct NoopEventSink;
#[async_trait]
impl EventSink for NoopEventSink {
async fn emit(&self, _event: &CloudEventV1) -> Result<(), CellosError> {
Ok(())
}
}
pub struct NoopExportSink;
#[async_trait]
impl ExportSink for NoopExportSink {
async fn push(
&self,
name: &str,
_path: &str,
_metadata: &ExportArtifactMetadata,
) -> Result<ExportReceipt, CellosError> {
Err(CellosError::ExportSink(format!(
"export requested for artifact {name:?} but no export sink is configured"
)))
}
}