Run trigger_state_refresh from the daily update job so OAuth2 tokens are
exchanged at least once per day, preventing Google refresh tokens from
expiring and persisting newly returned Microsoft ones.

This is done under a notifications config lock. Failure to do so may
lead to state file updates happening concurrently with other config
updates.

Signed-off-by: Arthur Bied-Charreton <[email protected]>
---
 src/bin/proxmox-daily-update.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/bin/proxmox-daily-update.rs b/src/bin/proxmox-daily-update.rs
index 42ce62d16..d54449fef 100644
--- a/src/bin/proxmox-daily-update.rs
+++ b/src/bin/proxmox-daily-update.rs
@@ -22,6 +22,13 @@ async fn wait_for_local_worker(upid_str: &str) -> Result<(), 
Error> {
     Ok(())
 }
 
+fn refresh_notification_state() -> Result<(), anyhow::Error> {
+    let _lock = pbs_config::notifications::lock_config()?;
+    let conf = pbs_config::notifications::config()?;
+    proxmox_notify::api::common::trigger_state_refresh(&conf)?;
+    Ok(())
+}
+
 /// Daily update
 async fn do_update(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let param = json!({});
@@ -61,6 +68,10 @@ async fn do_update(rpcenv: &mut dyn RpcEnvironment) -> 
Result<(), Error> {
         log::error!("error checking certificates: {err}");
     }
 
+    if let Err(err) = 
tokio::task::spawn_blocking(refresh_notification_state).await? {
+        log::error!("Error refreshing notification endpoints' internal state: 
{err}");
+    }
+
     // TODO: cleanup tasks like in PVE?
 
     Ok(())
-- 
2.47.3



Reply via email to