pub const COMMANDS_ALL: &str = "commands.all";
pub fn commands_group(name: &str) -> String {
format!("commands.group.{name}")
}
pub fn commands_pc(pc_id: &str) -> String {
format!("commands.pc.{pc_id}")
}
pub fn results(request_id: &str) -> String {
format!("results.{request_id}")
}
pub fn heartbeat(pc_id: &str) -> String {
format!("heartbeat.{pc_id}")
}
pub fn kill(exec_id: &str) -> String {
format!("kill.{exec_id}")
}
pub fn inventory(pc_id: &str, category: &str) -> String {
format!("inventory.{pc_id}.{category}")
}
pub fn events_started(exec_id: &str, pc_id: &str) -> String {
format!("events.started.{exec_id}.{pc_id}")
}
pub const EVENTS_STARTED_FILTER: &str = "events.started.>";
pub const INVENTORY_HW: &str = "hw";
pub const INVENTORY_SW: &str = "sw";
pub const INVENTORY_NET: &str = "net";
pub fn logs_fetch(pc_id: &str) -> String {
format!("logs.fetch.{pc_id}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn commands_all_constant() {
assert_eq!(COMMANDS_ALL, "commands.all");
}
#[test]
fn commands_group_formats_name() {
assert_eq!(commands_group("canary"), "commands.group.canary");
assert_eq!(commands_group("wave1"), "commands.group.wave1");
}
#[test]
fn commands_pc_formats_id() {
assert_eq!(commands_pc("minipc"), "commands.pc.minipc");
assert_eq!(commands_pc("PC1234"), "commands.pc.PC1234");
}
#[test]
fn results_formats_request_id() {
assert_eq!(results("req-1"), "results.req-1");
}
#[test]
fn heartbeat_formats_pc_id() {
assert_eq!(heartbeat("minipc"), "heartbeat.minipc");
}
#[test]
fn kill_formats_exec_id() {
assert_eq!(kill("exec-uuid-1"), "kill.exec-uuid-1");
}
#[test]
fn logs_fetch_formats_pc_id() {
assert_eq!(logs_fetch("minipc"), "logs.fetch.minipc");
}
#[test]
fn events_started_formats_exec_id_and_pc_id() {
assert_eq!(
events_started("exec-uuid-1", "minipc"),
"events.started.exec-uuid-1.minipc",
);
}
#[test]
fn events_started_filter_is_narrow_wildcard() {
assert_eq!(EVENTS_STARTED_FILTER, "events.started.>");
}
#[test]
fn inventory_formats_pc_id_and_category() {
assert_eq!(inventory("minipc", "hw"), "inventory.minipc.hw");
assert_eq!(inventory("minipc", INVENTORY_HW), "inventory.minipc.hw");
assert_eq!(inventory("minipc", INVENTORY_SW), "inventory.minipc.sw");
assert_eq!(inventory("minipc", INVENTORY_NET), "inventory.minipc.net");
}
}