Skip to content

Commit

Permalink
Add close to credential storage (#5283) (#5293)
Browse files Browse the repository at this point in the history
* Add close method to credential storage

* wip
  • Loading branch information
octol authored Dec 18, 2024
1 parent 3521f36 commit 53c28af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/credential-storage/src/backends/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <= ?",
Expand Down
4 changes: 4 additions & 0 deletions common/credential-storage/src/ephemeral_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 4 additions & 0 deletions common/credential-storage/src/persistent_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions common/credential-storage/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down

0 comments on commit 53c28af

Please sign in to comment.