refactor: wrap the encryption and file storage interface client in appstate with Arc as opposed to Box (#4949)

This commit is contained in:
Chethan Rao
2024-06-11 20:23:05 +05:30
committed by GitHub
parent 42cd769407
commit 88cf904f5b
4 changed files with 16 additions and 11 deletions

View File

@ -2,7 +2,10 @@
//! Module for managing file storage operations with support for multiple storage schemes.
//!
use std::fmt::{Display, Formatter};
use std::{
fmt::{Display, Formatter},
sync::Arc,
};
use common_utils::errors::CustomResult;
@ -39,11 +42,11 @@ impl FileStorageConfig {
}
/// Retrieves the appropriate file storage client based on the file storage configuration.
pub async fn get_file_storage_client(&self) -> Box<dyn FileStorageInterface> {
pub async fn get_file_storage_client(&self) -> Arc<dyn FileStorageInterface> {
match self {
#[cfg(feature = "aws_s3")]
Self::AwsS3 { aws_s3 } => Box::new(aws_s3::AwsFileStorageClient::new(aws_s3).await),
Self::FileSystem => Box::new(file_system::FileSystem),
Self::AwsS3 { aws_s3 } => Arc::new(aws_s3::AwsFileStorageClient::new(aws_s3).await),
Self::FileSystem => Arc::new(file_system::FileSystem),
}
}
}

View File

@ -2,6 +2,8 @@
//! Encryption management util module
//!
use std::sync::Arc;
use common_utils::errors::CustomResult;
use hyperswitch_interfaces::encryption_interface::{
EncryptionError, EncryptionManagementInterface,
@ -42,12 +44,12 @@ impl EncryptionManagementConfig {
/// Retrieves the appropriate encryption client based on the configuration.
pub async fn get_encryption_management_client(
&self,
) -> CustomResult<Box<dyn EncryptionManagementInterface>, EncryptionError> {
) -> CustomResult<Arc<dyn EncryptionManagementInterface>, EncryptionError> {
Ok(match self {
#[cfg(feature = "aws_kms")]
Self::AwsKms { aws_kms } => Box::new(aws_kms::core::AwsKmsClient::new(aws_kms).await),
Self::AwsKms { aws_kms } => Arc::new(aws_kms::core::AwsKmsClient::new(aws_kms).await),
Self::NoEncryption => Box::new(NoEncryption),
Self::NoEncryption => Arc::new(NoEncryption),
})
}
}