summaryrefslogtreecommitdiff
path: root/src/vapid/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vapid/app.rs')
-rw-r--r--src/vapid/app.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/vapid/app.rs b/src/vapid/app.rs
index 8886c9f..ddb1f4d 100644
--- a/src/vapid/app.rs
+++ b/src/vapid/app.rs
@@ -1,4 +1,4 @@
-use chrono::TimeDelta;
+use chrono::{TimeDelta, Utc};
use sqlx::SqlitePool;
use super::{History, repo, repo::Provider as _};
@@ -18,6 +18,21 @@ impl<'a> Vapid<'a> {
Self { db, events }
}
+ pub async fn rotate_key(&self, rotate_at: &DateTime) -> Result<(), sqlx::Error> {
+ let mut tx = self.db.begin().await?;
+ // This is called from a separate CLI utility (see `cli.rs`), and we _can't_ deliver events
+ // to active clients from another process, so don't do anything that would require us to
+ // send events, like generating a new key.
+ //
+ // Instead, the server's next `refresh_key` call will generate a key and notify clients
+ // of the change. All we have to do is remove the existing key, so that the server can know
+ // to do so.
+ tx.vapid().clear().await?;
+ tx.commit().await?;
+
+ Ok(())
+ }
+
pub async fn refresh_key(&self, ensure_at: &DateTime) -> Result<(), Error> {
let mut tx = self.db.begin().await?;
let key = tx.vapid().current().await.optional()?;