Skip to content

Add close to credential storage #5283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading