From 8fb24a2c0a1ec2cfc3b9b72dfe1c17cee5ab0772 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 3 May 2021 11:39:59 +0200 Subject: [PATCH] daily-update: check acme certificates Signed-off-by: Wolfgang Bumiller --- src/bin/proxmox-daily-update.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/bin/proxmox-daily-update.rs b/src/bin/proxmox-daily-update.rs index 83c6b80c..be3bfe44 100644 --- a/src/bin/proxmox-daily-update.rs +++ b/src/bin/proxmox-daily-update.rs @@ -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();