1use serde::Deserialize;
2
3#[derive(Debug, Clone, Deserialize)]
8pub struct CortexConfig {
9 pub server_url: String,
10 pub pat: String,
12 pub software_id: String,
14 #[serde(default = "default_timeout")]
15 pub timeout: u64,
16 #[serde(default = "default_heartbeat_interval")]
18 pub heartbeat_interval: u64,
19 #[serde(default)]
22 pub software_public_key: Option<String>,
23}
24
25fn default_timeout() -> u64 {
26 30
27}
28
29fn default_heartbeat_interval() -> u64 {
30 60
31}
32
33impl CortexConfig {
34 pub fn new(
35 server_url: impl Into<String>,
36 pat: impl Into<String>,
37 software_id: impl Into<String>,
38 ) -> Self {
39 Self {
40 server_url: server_url.into(),
41 pat: pat.into(),
42 software_id: software_id.into(),
43 timeout: 30,
44 heartbeat_interval: 60,
45 software_public_key: None,
46 }
47 }
48
49 pub fn with_timeout(mut self, timeout: u64) -> Self {
50 self.timeout = timeout;
51 self
52 }
53
54 pub fn with_software_public_key(mut self, pk: impl Into<String>) -> Self {
56 self.software_public_key = Some(pk.into());
57 self
58 }
59
60 pub fn with_software_id(mut self, software_id: impl Into<String>) -> Self {
62 self.software_id = software_id.into();
63 self
64 }
65
66 pub fn with_heartbeat_interval(mut self, secs: u64) -> Self {
68 self.heartbeat_interval = secs;
69 self
70 }
71
72 pub fn without_heartbeat(mut self) -> Self {
74 self.heartbeat_interval = 0;
75 self
76 }
77}