use rho_protocol::{CredentialStoreKind, CredentialStoreStatus, StoreSelectedBy};
use super::report::{DoctorCheck, DoctorCheckId, DoctorStatus};
use crate::credential_store::wire;
pub(super) const LABEL: &str = "Daemon credential store";
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum DaemonStore {
NotRunning,
Unanswered(String),
Reported(CredentialStoreStatus),
}
pub(crate) fn daemon_store_check(store: &DaemonStore) -> DoctorCheck {
let row = |status, summary: String| {
DoctorCheck::new(DoctorCheckId::DaemonCredentialStore, LABEL, status, summary)
};
match store {
DaemonStore::NotRunning => row(DoctorStatus::Info, "daemon not running".into()).with_hint(
"it starts when a client needs it; run `rho daemon start`, then `rho doctor` again to check the store it can reach",
),
DaemonStore::Unanswered(reason) => {
row(DoctorStatus::Warn, "daemon did not answer".into()).with_hint(reason.clone())
}
DaemonStore::Reported(status) => {
let (name, chosen) = wire::words(status);
match &status.unreachable {
None => row(DoctorStatus::Ok, format!("{name} store")).with_hint(format!("chosen {chosen}")),
Some(reason) => {
let (severity, choose) = match status.selected_by {
StoreSelectedBy::Default => (
DoctorStatus::Warn,
"`rho login <provider>` asks which store to use",
),
StoreSelectedBy::Environment => (
DoctorStatus::Fail,
"change RHO_CREDENTIAL_STORE where the daemon starts, then run `rho daemon stop`",
),
StoreSelectedBy::Config => (
DoctorStatus::Fail,
match status.store {
CredentialStoreKind::File => {
"choose another with `rho credential-store set os`"
}
_ => "choose another with `rho credential-store set file`",
},
),
_ => (DoctorStatus::Warn, "check how the daemon chose it"),
};
row(severity, format!("{name} store unreachable")).with_hint(format!(
"{reason}; {choose}, or stop the daemon with `rho daemon stop` so a client where the store works starts it again"
))
}
}
}
}
}
#[cfg(test)]
#[path = "daemon_store_tests.rs"]
mod tests;