use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct CortexConfig {
pub server_url: String,
pub pat: String,
pub software_id: String,
#[serde(default = "default_timeout")]
pub timeout: u64,
#[serde(default = "default_heartbeat_interval")]
pub heartbeat_interval: u64,
#[serde(default)]
pub software_public_key: Option<String>,
}
fn default_timeout() -> u64 {
30
}
fn default_heartbeat_interval() -> u64 {
60
}
impl CortexConfig {
pub fn new(
server_url: impl Into<String>,
pat: impl Into<String>,
software_id: impl Into<String>,
) -> Self {
Self {
server_url: server_url.into(),
pat: pat.into(),
software_id: software_id.into(),
timeout: 30,
heartbeat_interval: 60,
software_public_key: None,
}
}
pub fn with_timeout(mut self, timeout: u64) -> Self {
self.timeout = timeout;
self
}
pub fn with_software_public_key(mut self, pk: impl Into<String>) -> Self {
self.software_public_key = Some(pk.into());
self
}
pub fn with_software_id(mut self, software_id: impl Into<String>) -> Self {
self.software_id = software_id.into();
self
}
pub fn with_heartbeat_interval(mut self, secs: u64) -> Self {
self.heartbeat_interval = secs;
self
}
pub fn without_heartbeat(mut self) -> Self {
self.heartbeat_interval = 0;
self
}
}