wait for hold certs to be generated

This commit is contained in:
daywalker90 2026-01-05 14:49:33 +01:00 committed by daywalker90
parent c956338bcd
commit 5c5f49de29

View file

@ -268,6 +268,14 @@ async fn check_hold_support(plugin: Plugin<PluginState>) -> Result<(), anyhow::E
cert_dir.to_str().unwrap()
);
let max_retries = 10;
let mut retries = 0;
while retries < max_retries && !do_certificates_exist(&cert_dir) {
log::debug!("Hold certificates incomplete. Waiting...");
time::sleep(Duration::from_millis(500)).await;
retries += 1;
}
let ca_cert = tokio::fs::read(cert_dir.join("ca.pem")).await?;
let client_cert = tokio::fs::read(cert_dir.join("client.pem")).await?;
let client_key = tokio::fs::read(cert_dir.join("client-key.pem")).await?;
@ -289,3 +297,12 @@ async fn check_hold_support(plugin: Plugin<PluginState>) -> Result<(), anyhow::E
Ok(())
}
fn do_certificates_exist(cert_dir: &Path) -> bool {
let required_files = ["client.pem", "client-key.pem", "ca.pem"];
required_files.iter().all(|file| {
let path = cert_dir.join(file);
path.exists() && path.metadata().map(|m| m.len() > 0).unwrap_or(false)
})
}