From 53c28af847e9db9df17c44b070b6917ef75c3972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 18 Dec 2024 21:51:00 +0100 Subject: [PATCH] Add close to credential storage (#5283) (#5293) * Add close method to credential storage * wip --- common/credential-storage/src/backends/sqlite.rs | 5 +++++ common/credential-storage/src/ephemeral_storage.rs | 4 ++++ common/credential-storage/src/persistent_storage/mod.rs | 4 ++++ common/credential-storage/src/storage.rs | 2 ++ 4 files changed, 15 insertions(+) diff --git a/common/credential-storage/src/backends/sqlite.rs b/common/credential-storage/src/backends/sqlite.rs index 9267bbddb36..dec08990644 100644 --- a/common/credential-storage/src/backends/sqlite.rs +++ b/common/credential-storage/src/backends/sqlite.rs @@ -23,6 +23,11 @@ impl SqliteEcashTicketbookManager { SqliteEcashTicketbookManager { connection_pool } } + /// Closes the connection pool. + pub async fn close(&self) { + self.connection_pool.close().await + } + pub(crate) async fn cleanup_expired(&self, deadline: Date) -> Result<(), sqlx::Error> { sqlx::query!( "DELETE FROM ecash_ticketbook WHERE expiration_date <= ?", diff --git a/common/credential-storage/src/ephemeral_storage.rs b/common/credential-storage/src/ephemeral_storage.rs index 91436d4d8c1..b6a113f4149 100644 --- a/common/credential-storage/src/ephemeral_storage.rs +++ b/common/credential-storage/src/ephemeral_storage.rs @@ -43,6 +43,10 @@ impl Debug for EphemeralStorage { impl Storage for EphemeralStorage { type StorageError = StorageError; + async fn close(&self) { + // nothing to do here + } + async fn cleanup_expired(&self) -> Result<(), Self::StorageError> { self.storage_manager.cleanup_expired().await; Ok(()) diff --git a/common/credential-storage/src/persistent_storage/mod.rs b/common/credential-storage/src/persistent_storage/mod.rs index e8c9eca5aa9..32b6f581dee 100644 --- a/common/credential-storage/src/persistent_storage/mod.rs +++ b/common/credential-storage/src/persistent_storage/mod.rs @@ -89,6 +89,10 @@ impl PersistentStorage { impl Storage for PersistentStorage { type StorageError = StorageError; + async fn close(&self) { + self.storage_manager.close().await + } + /// remove all expired ticketbooks and expiration date signatures async fn cleanup_expired(&self) -> Result<(), Self::StorageError> { let ecash_yesterday = ecash_today().date().previous_day().unwrap(); diff --git a/common/credential-storage/src/storage.rs b/common/credential-storage/src/storage.rs index 19ddc44e86a..4c0602ea855 100644 --- a/common/credential-storage/src/storage.rs +++ b/common/credential-storage/src/storage.rs @@ -22,6 +22,8 @@ use std::error::Error; pub trait Storage: Send + Sync { type StorageError: Error; + async fn close(&self); + /// remove all expired ticketbooks and expiration date signatures async fn cleanup_expired(&self) -> Result<(), Self::StorageError>;