use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum SandboxStatus {
Running,
Stopped,
Creating,
Error,
#[serde(other)]
Unknown,
}
#[deprecated(since = "1.1.0", note = "use SandboxStatus")]
pub type ContainerStatus = SandboxStatus;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sandbox {
pub id: String,
#[serde(default)]
pub name: String,
#[serde(default)]
pub image: String,
#[serde(default)]
pub status: String,
#[serde(default)]
pub created_at: String,
#[serde(default)]
pub started_at: Option<String>,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub environment: HashMap<String, String>,
}
#[deprecated(since = "1.1.0", note = "use Sandbox")]
pub type Container = Sandbox;
#[derive(Debug, Clone, Serialize, Default)]
pub struct CreateSandboxRequest {
pub image: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
pub environment: HashMap<String, String>,
#[serde(skip_serializing_if = "HashMap::is_empty", default)]
pub labels: HashMap<String, String>,
}
#[deprecated(since = "1.1.0", note = "use CreateSandboxRequest")]
pub type CreateContainerRequest = CreateSandboxRequest;
impl CreateSandboxRequest {
pub fn new(image: impl Into<String>) -> Self {
Self {
image: image.into(),
..Default::default()
}
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.environment.insert(key.into(), value.into());
self
}
pub fn label(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.labels.insert(key.into(), value.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileInfo {
pub name: String,
pub path: String,
pub size: u64,
pub mode: String,
pub mod_time: String,
pub is_dir: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct ResizeMessage {
#[serde(rename = "type")]
pub msg_type: String,
pub cols: u16,
pub rows: u16,
}
impl ResizeMessage {
pub fn new(cols: u16, rows: u16) -> Self {
Self {
msg_type: "resize".into(),
cols,
rows,
}
}
}