daily-update: check acme certificates

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-05-03 11:39:59 +02:00 committed by Dietmar Maurer
parent 4b5d9b6e64
commit 8fb24a2c0a

View File

@ -50,13 +50,41 @@ async fn do_update(
};
wait_for_local_worker(upid.as_str().unwrap()).await?;
// TODO: certificate checks/renewal/... ?
match check_acme_certificates(rpcenv).await {
Ok(()) => (),
Err(err) => {
eprintln!("error checking certificates: {}", err);
}
}
// TODO: cleanup tasks like in PVE?
Ok(Value::Null)
}
async fn check_acme_certificates(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
let (config, _) = proxmox_backup::config::node::config()?;
// do we even have any acme domains configures?
if config.acme_domains().next().is_none() {
return Ok(());
}
if !api2::node::certificates::cert_expires_soon()? {
println!("Certificate does not expire within the next 30 days, not renewing.");
return Ok(());
}
let info = &api2::node::certificates::API_METHOD_RENEW_ACME_CERT;
let result = match info.handler {
ApiHandler::Sync(handler) => (handler)(json!({}), info, rpcenv)?,
_ => unreachable!(),
};
wait_for_local_worker(result.as_str().unwrap()).await?;
Ok(())
}
fn main() {
proxmox_backup::tools::setup_safe_path_env();