()
| 107 | |
| 108 | #[rocket::main] |
| 109 | async fn main() -> Result<()> { |
| 110 | { |
| 111 | use tracing_subscriber::{fmt, EnvFilter}; |
| 112 | let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); |
| 113 | fmt().with_env_filter(filter).with_ansi(false).init(); |
| 114 | } |
| 115 | let args = Args::parse(); |
| 116 | |
| 117 | let figment = config::load_config_figment(args.config.as_deref()); |
| 118 | let config: KmsConfig = figment.focus("core").extract()?; |
| 119 | |
| 120 | if config.onboard.enabled && !config.keys_exists() { |
| 121 | info!("Onboarding"); |
| 122 | run_onboard_service(config.clone(), figment.clone()).await?; |
| 123 | if !config.keys_exists() { |
| 124 | bail!("Failed to onboard"); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | info!("Updating certs"); |
| 129 | if let Err(err) = onboard_service::update_certs(&config).await { |
| 130 | warn!("Failed to update certs: {err}"); |
| 131 | }; |
| 132 | |
| 133 | info!("Starting KMS"); |
| 134 | info!("Supported methods:"); |
| 135 | for method in main_service::rpc_methods() { |
| 136 | info!(" /prpc/{method}"); |
| 137 | } |
| 138 | |
| 139 | let pccs_url = config.pccs_url.clone(); |
| 140 | let metrics_enabled = config.metrics.enabled; |
| 141 | let state = main_service::KmsState::new(config).context("Failed to initialize KMS state")?; |
| 142 | let figment = figment |
| 143 | .clone() |
| 144 | .merge(Serialized::defaults(figment.find_value("rpc")?)); |
| 145 | let mut rocket = rocket::custom(figment) |
| 146 | .attach(AdHoc::on_response("Add app version header", |_req, res| { |
| 147 | Box::pin(async move { |
| 148 | res.set_raw_header("X-App-Version", app_version()); |
| 149 | }) |
| 150 | })) |
| 151 | .mount( |
| 152 | "/prpc", |
| 153 | ra_rpc::prpc_routes!(KmsState, RpcHandler, trim: "KMS."), |
| 154 | ) |
| 155 | .manage(state); |
| 156 | |
| 157 | if metrics_enabled { |
| 158 | info!("Prometheus metrics endpoint enabled at /metrics"); |
| 159 | rocket = rocket |
| 160 | .attach(AdHoc::on_response( |
| 161 | "Record KMS attestation metrics", |
| 162 | |req, res| Box::pin(async move { record_attestation_metrics(req, res) }), |
| 163 | )) |
| 164 | .mount("/", rocket::routes![metrics]); |
| 165 | } |
| 166 |
nothing calls this directly
no test coverage detected