1pub const COMMANDS_ALL: &str = "commands.all";
2
3pub fn commands_group(name: &str) -> String {
4 format!("commands.group.{name}")
5}
6
7pub fn commands_pc(pc_id: &str) -> String {
8 format!("commands.pc.{pc_id}")
9}
10
11pub fn results(request_id: &str) -> String {
19 format!("results.{request_id}")
20}
21
22pub fn heartbeat(pc_id: &str) -> String {
23 format!("heartbeat.{pc_id}")
24}
25
26pub fn kill(exec_id: &str) -> String {
31 format!("kill.{exec_id}")
32}
33
34pub fn inventory(pc_id: &str, category: &str) -> String {
35 format!("inventory.{pc_id}.{category}")
36}
37
38pub const INVENTORY_HW: &str = "hw";
39pub const INVENTORY_SW: &str = "sw";
40pub const INVENTORY_NET: &str = "net";
41
42pub fn logs_fetch(pc_id: &str) -> String {
46 format!("logs.fetch.{pc_id}")
47}
48
49#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn commands_all_constant() {
61 assert_eq!(COMMANDS_ALL, "commands.all");
62 }
63
64 #[test]
65 fn commands_group_formats_name() {
66 assert_eq!(commands_group("canary"), "commands.group.canary");
67 assert_eq!(commands_group("wave1"), "commands.group.wave1");
68 }
69
70 #[test]
71 fn commands_pc_formats_id() {
72 assert_eq!(commands_pc("minipc"), "commands.pc.minipc");
73 assert_eq!(commands_pc("PC1234"), "commands.pc.PC1234");
74 }
75
76 #[test]
77 fn results_formats_request_id() {
78 assert_eq!(results("req-1"), "results.req-1");
79 }
80
81 #[test]
82 fn heartbeat_formats_pc_id() {
83 assert_eq!(heartbeat("minipc"), "heartbeat.minipc");
84 }
85
86 #[test]
87 fn kill_formats_exec_id() {
88 assert_eq!(kill("exec-uuid-1"), "kill.exec-uuid-1");
89 }
90
91 #[test]
92 fn logs_fetch_formats_pc_id() {
93 assert_eq!(logs_fetch("minipc"), "logs.fetch.minipc");
94 }
95
96 #[test]
97 fn inventory_formats_pc_id_and_category() {
98 assert_eq!(inventory("minipc", "hw"), "inventory.minipc.hw");
99 assert_eq!(inventory("minipc", INVENTORY_HW), "inventory.minipc.hw");
100 assert_eq!(inventory("minipc", INVENTORY_SW), "inventory.minipc.sw");
101 assert_eq!(inventory("minipc", INVENTORY_NET), "inventory.minipc.net");
102 }
103}