use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ContextMeta {
pub name: String,
pub metadata: ContextMetadata,
pub endpoints: ContextEndpoints,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ContextMetadata {
pub description: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextEndpoints {
pub docker: DockerEndpoint,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DockerEndpoint {
pub host: String,
#[serde(default, rename = "SkipTLSVerify")]
pub skip_tls_verify: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DockerConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub current_context: Option<String>,
#[serde(flatten)]
pub other: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct ContextStatus {
pub context_exists: bool,
pub is_default: bool,
pub socket_path: PathBuf,
pub socket_exists: bool,
}
impl std::fmt::Display for ContextStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "ArcBox Docker Integration Status:")?;
writeln!(
f,
" Context exists: {}",
if self.context_exists { "yes" } else { "no" }
)?;
writeln!(
f,
" Is default: {}",
if self.is_default { "yes" } else { "no" }
)?;
writeln!(f, " Socket path: {}", self.socket_path.display())?;
write!(
f,
" Socket exists: {}",
if self.socket_exists { "yes" } else { "no" }
)
}
}