use std::error::Error;
use std::path::PathBuf;
use did_hosting_common::server::health;
use crate::config::AppConfig;
pub async fn run_health(config_path: Option<PathBuf>) -> Result<(), Box<dyn Error>> {
health::header("did-hosting-control", env!("CARGO_PKG_VERSION"));
let config = match AppConfig::load(config_path) {
Ok(c) => {
health::section("Configuration");
health::check_config_loaded(&c.config_path);
health::check_value("public_url", &c.public_url);
health::check_value("server_did", &c.server_did);
health::check_value("did_hosting_url", &c.did_hosting_url);
health::check_value("mediator_did", &c.mediator_did);
Some(c)
}
Err(e) => {
health::section("Configuration");
health::fail(&format!("Config load failed: {e}"));
None
}
};
health::section("Compile Features");
health::print_feature("store-fjall", cfg!(feature = "store-fjall"));
health::print_feature("store-redis", cfg!(feature = "store-redis"));
health::print_feature("store-dynamodb", cfg!(feature = "store-dynamodb"));
health::print_feature("store-firestore", cfg!(feature = "store-firestore"));
health::print_feature("store-cosmosdb", cfg!(feature = "store-cosmosdb"));
health::print_feature("keyring", cfg!(feature = "keyring"));
health::print_feature("aws-secrets", cfg!(feature = "aws-secrets"));
health::print_feature("gcp-secrets", cfg!(feature = "gcp-secrets"));
health::print_feature("ui", cfg!(feature = "ui"));
let config = match config {
Some(c) => c,
None => {
eprintln!();
return Ok(());
}
};
health::section("Secrets");
health::check_secrets(&config.secrets, &config.config_path).await;
health::section("Store");
health::check_store(&config.store).await;
if let Some(ref did) = config.server_did {
health::section("DID Resolution");
health::check_did_resolution("Server DID resolves", did).await;
}
if let Some(ref did) = config.mediator_did {
health::section("Mediator DID Resolution");
health::check_did_resolution("Mediator DID resolves", did).await;
}
if let Some(ref url) = config.did_hosting_url {
health::section("DID Hosting Connectivity");
let health_url = format!("{url}/health");
health::check_url_reachable("DID hosting reachable", &health_url).await;
}
eprintln!();
Ok(())
}