use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
pub fn state_dir() -> PathBuf {
dirs::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(".starling")
}
pub fn socket_path() -> PathBuf {
state_dir().join("daemon.sock")
}
pub fn pid_path() -> PathBuf {
state_dir().join("daemon.pid")
}
pub fn log_path() -> PathBuf {
state_dir().join("daemon.log")
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ResourceSnapshot {
pub name: String,
pub kind: String,
pub update_status: String,
pub runtime_status: String,
pub pod: Option<String>,
pub url: Option<String>,
pub build_count: u32,
pub last_deploy: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct InstanceState {
pub id: String,
pub name: String,
pub dir: String,
pub pid: u32,
pub resources: Vec<ResourceSnapshot>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct RouteInfo {
pub hostname: String,
pub port: u16,
pub instance: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct DashboardState {
pub instances: Vec<InstanceState>,
pub routes: Vec<RouteInfo>,
pub proxy_port: u16,
pub tld: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Command {
Trigger { resource: String },
Restart { resource: String },
Shutdown,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
Ping,
Register { name: String, dir: String, pid: u32 },
Deregister { instance: String },
Update {
instance: String,
resources: Vec<ResourceSnapshot>,
logs: HashMap<String, Vec<String>>,
},
AllocatePort { instance: String },
RegisterRoute {
instance: String,
hostname: String,
port: u16,
},
RemoveRoute { hostname: String },
GetState,
GetLogs { instance: String, resource: String },
PollCommands { instance: String },
Trigger { instance: String, resource: String },
Restart { instance: String, resource: String },
ShutdownProject { dir: String },
ShutdownDaemon,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
Ok,
Registered { instance: String },
Port { port: u16 },
State(DashboardState),
Logs(Vec<String>),
Commands(Vec<Command>),
ShutdownQueued { instances: Vec<InstanceState> },
Error(String),
}