use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DockerConfig {
pub username: String,
pub password: String,
pub registry: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdvancedFeatures {
pub tproxy: bool,
pub kms: bool,
pub public_sys_info: bool,
pub public_logs: bool,
pub docker_config: DockerConfig,
pub listed: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComposeManifest {
pub name: String,
pub features: Vec<String>,
pub docker_compose_file: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VmConfig {
pub name: String,
pub compose_manifest: ComposeManifest,
pub vcpu: u32,
pub memory: u32,
pub disk_size: u32,
pub teepod_id: u64,
pub image: String,
pub advanced_features: AdvancedFeatures,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EncryptedEnv {
pub key: String,
pub value: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct DeploymentResponse {
pub id: u64,
pub status: String,
pub details: Option<HashMap<String, serde_json::Value>>,
}
impl<'de> Deserialize<'de> for DeploymentResponse {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
let value = serde_json::Value::deserialize(deserializer)?;
let obj = match value.as_object() {
Some(obj) => obj,
None => return Err(D::Error::custom("Expected object for DeploymentResponse")),
};
let id = if let Some(id_value) = obj.get("id") {
if let Some(id_num) = id_value.as_u64() {
id_num
} else if let Some(id_str) = id_value.as_str() {
id_str.parse::<u64>().unwrap_or(0)
} else {
0 }
} else if let Some(id_value) = obj.get("uuid") {
if let Some(id_num) = id_value.as_u64() {
id_num
} else if let Some(id_str) = id_value.as_str() {
id_str.parse::<u64>().unwrap_or(0)
} else {
0 }
} else if let Some(id_value) = obj.get("app_id") {
if let Some(id_str) = id_value.as_str() {
if id_str.starts_with("app_") {
id_str[4..].parse::<u64>().unwrap_or(0)
} else {
id_str.parse::<u64>().unwrap_or(0)
}
} else {
0 }
} else {
use rand::Rng;
rand::thread_rng().gen()
};
let status = obj
.get("status")
.and_then(|v| v.as_str())
.unwrap_or("pending")
.to_string();
let mut details = HashMap::new();
for (k, v) in obj {
details.insert(k.clone(), v.clone());
}
Ok(DeploymentResponse {
id,
status,
details: Some(details),
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComposeResponse {
pub compose_file: serde_json::Value,
pub env_pubkey: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PubkeyResponse {
pub app_env_encrypt_pubkey: String,
pub app_id: String,
pub app_id_salt: String,
pub compose_manifest: ComposeManifest,
pub disk_size: u64,
pub encrypted_env: String,
pub image: String,
pub listed: bool,
pub memory: u64,
pub name: String,
pub ports: Option<Vec<String>>,
pub teepod_id: u64,
pub user_id: Option<String>,
pub vcpu: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComposeManifestResponse {
pub bash_script: Option<String>,
pub docker_compose_file: String,
pub docker_config: DockerConfig,
pub features: Vec<String>,
pub kms_enabled: bool,
pub manifest_version: u64,
pub name: String,
pub pre_launch_script: String,
pub public_logs: bool,
pub public_sysinfo: bool,
pub runner: String,
pub salt: String,
pub tproxy_enabled: bool,
pub version: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeePodDiscoveryResponse {
pub capacity: TeePodCapacity,
pub nodes: Vec<TeePodNode>,
pub tier: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeePodCapacity {
pub max_disk: u64,
pub max_instances: u64,
pub max_memory: u64,
pub max_vcpu: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeePodNode {
pub images: Vec<TeePodImage>,
pub listed: bool,
pub name: String,
pub remaining_cvm_slots: u64,
pub remaining_memory: f64,
pub remaining_vcpu: f64,
pub resource_score: f64,
pub teepod_id: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeePodImage {
pub bios: String,
pub cmdline: String,
pub description: String,
pub hda: Option<String>,
pub initrd: String,
pub is_dev: bool,
pub kernel: String,
pub name: String,
pub rootfs: String,
pub rootfs_hash: String,
pub shared_ro: bool,
pub version: Vec<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkInfoResponse {
pub is_online: bool,
pub is_public: bool,
pub error: Option<String>,
pub internal_ip: String,
pub latest_handshake: String,
pub public_urls: PublicUrls,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublicUrls {
pub app: String,
pub instance: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiskInfo {
pub name: String,
pub mount_point: Option<String>,
pub total_size: u64,
pub free_size: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemInfo {
pub os_name: String,
pub os_version: String,
pub kernel_version: String,
pub cpu_model: String,
pub num_cpus: u32,
pub total_memory: u64,
pub available_memory: u64,
pub used_memory: u64,
pub free_memory: u64,
pub total_swap: u64,
pub used_swap: u64,
pub free_swap: u64,
pub uptime: u64,
pub loadavg_one: f32,
pub loadavg_five: f32,
pub loadavg_fifteen: f32,
pub disks: Vec<DiskInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemStatsResponse {
pub is_online: bool,
pub is_public: bool,
pub error: Option<String>,
pub sysinfo: SystemInfo,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CvmInfo {
pub id: u64,
pub status: String,
pub name: String,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CvmStateResponse {
pub status: String,
pub is_running: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AttestationResponse {
#[serde(default)]
pub tcb_info: serde_json::Value,
#[serde(default)]
pub app_certificates: serde_json::Value,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}