use serde::{Deserialize, Serialize};
#[cfg(target_family = "unix")]
use nix::sys::utsname::uname;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[cfg_attr(feature = "apidocs", derive(utoipa::ToSchema))]
pub struct RuntimeMetadata {
pub rayhunter_version: String,
pub system_os: String,
pub arch: String,
}
impl Default for RuntimeMetadata {
fn default() -> Self {
Self::new()
}
}
impl RuntimeMetadata {
pub fn new() -> Self {
let build_target = RuntimeMetadata {
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
arch: std::env::consts::ARCH.to_string(),
system_os: std::env::consts::OS.to_string(),
};
#[cfg(target_family = "windows")]
return build_target;
#[cfg(target_family = "unix")]
match uname() {
Ok(utsname) => RuntimeMetadata {
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
arch: format!("{}", utsname.machine().to_string_lossy()),
system_os: format!(
"{} {}",
utsname.sysname().to_string_lossy(),
utsname.release().to_string_lossy(),
),
},
Err(_) => build_target,
}
}
}