use std::path::{Path, PathBuf};
use super::Area;
use super::human::Place;
use super::rows::Report;
use crate::home::Home;
#[cfg(not(any(unix, windows)))]
mod other;
#[cfg(unix)]
mod unix;
#[cfg(windows)]
mod windows;
#[cfg(not(any(unix, windows)))]
use other as platform;
#[cfg(unix)]
use unix as platform;
#[cfg(windows)]
use windows as platform;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct Found {
pub shown: String,
pub problem: Option<String>,
pub readable: Option<String>,
}
fn files(home: &Home) -> Vec<(&'static str, PathBuf, bool)> {
vec![
("state directory", home.root().to_path_buf(), false),
("lock", home.lock_path(), false),
("policy", home.policy_path(), false),
("policy base", home.policy_base_path(), false),
("approvals", home.grants_path(), false),
("allow rules", home.overlay_path(), false),
("trust", home.trust_path(), false),
("hosts", home.hosts_path(), false),
("environment", home.environment_path(), false),
("signers", home.signers_path(), false),
("packs", home.packs_path(), false),
("audit delivery", home.delivery_config_path(), false),
("audit log", home.audit_path(), false),
("audit key", crate::audit_key::path(home), true),
("audit signing key", crate::audit_signing::path(home), true),
("gate secret", crate::gate::path(home), true),
("proxy key", crate::proxy_session::key_path(home), true),
("proxy CA key", crate::proxy_ca::key_path(home), true),
]
}
pub(super) fn rows(report: &mut Report, home: &Home) {
platform::directory(report, home);
let Some(me) = platform::current_user() else {
report.note_at(platform::NOT_CHECKED, Place::OpenMoat);
return;
};
for (what, path, key) in files(home) {
let Some(found) = platform::inspect(&path, me) else {
continue;
};
let label = format!("{what:<17}");
report.note_at(
&format!("{label}{} {}", path.display(), found.shown),
Place::Details,
);
if let Some(problem) = &found.problem {
report.line(Area::State, false, row(&label, &path, problem));
} else if let Some(readable) = found.readable.as_ref().filter(|_| !key) {
report.warn(&row(&label, &path, readable));
}
}
}
fn row(label: &str, path: &Path, text: &str) -> String {
format!("{label}{} {text}", path.display())
}
#[cfg(test)]
mod tests;