You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
use std::{ |
|
collections::HashMap, |
|
time::SystemTime |
|
}; |
|
use crate::{ |
|
contracts::*, |
|
UID, |
|
exec_job, |
|
utils::vec_to_string, |
|
models::* |
|
}; |
|
|
|
use guess_host_triple::guess_host_triple; |
|
|
|
pub async fn gather() -> IAgent { |
|
|
|
async fn run_cmd_fast(cmd: String) -> String { |
|
let job = exec_job( |
|
JobMeta::from_shell_arc(cmd) |
|
).await; |
|
let job_result = match job.unwrap().data.unwrap() { |
|
Ok(output) => output.multiline(), |
|
Err(e) => e.to_string() |
|
}; |
|
JobOutput::from_multiline(&job_result) |
|
.map(|o| vec_to_string(&o.into_appropriate())) |
|
.unwrap_or(job_result) |
|
} |
|
|
|
#[cfg(unix)] |
|
IAgent { |
|
alias: None, |
|
id: UID.clone(), |
|
hostname: run_cmd_fast("hostname".to_string()).await, |
|
is_root: &run_cmd_fast("id -u".to_string()).await == "0", |
|
is_root_allowed: false, //TODO |
|
platform: guess_host_triple().unwrap_or("Error").to_string(), |
|
status: None, //TODO |
|
token: None, //TODO |
|
username: run_cmd_fast("id -un".to_string()).await, |
|
} |
|
} |
|
|
|
|
|
#[cfg(test)] |
|
mod tests { |
|
use super::*; |
|
|
|
#[tokio::test] |
|
async fn test_gather() { |
|
let cli_info = gather().await; |
|
assert_eq!( |
|
&cli_info.username, |
|
"plazmoid" |
|
) |
|
} |
|
|
|
}
|
|
|