Skip to content

Commit

Permalink
refactor: wrap the encryption and file storage interface client in ap…
Browse files Browse the repository at this point in the history
…pstate with `Arc` as opposed to `Box` (#4949)
  • Loading branch information
Chethan-rao committed Jun 11, 2024
1 parent 42cd769 commit 88cf904
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/drainer/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct CmdLineConf {
#[derive(Clone)]
pub struct AppState {
pub conf: Arc<Settings<RawSecret>>,
pub encryption_client: Box<dyn EncryptionManagementInterface>,
pub encryption_client: Arc<dyn EncryptionManagementInterface>,
}

impl AppState {
Expand Down
11 changes: 7 additions & 4 deletions crates/external_services/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! Encryption management util module
//!

use std::sync::Arc;

use common_utils::errors::CustomResult;
use hyperswitch_interfaces::encryption_interface::{
EncryptionError, EncryptionManagementInterface,
Expand Down Expand Up @@ -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),
})
}
}
6 changes: 3 additions & 3 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct SessionState {
pub email_client: Arc<dyn EmailService>,
#[cfg(feature = "olap")]
pub pool: AnalyticsProvider,
pub file_storage_client: Box<dyn FileStorageInterface>,
pub file_storage_client: Arc<dyn FileStorageInterface>,
pub request_id: Option<RequestId>,
pub base_url: String,
pub tenant: String,
Expand Down Expand Up @@ -144,8 +144,8 @@ pub struct AppState {
#[cfg(feature = "olap")]
pub opensearch_client: Arc<OpenSearchClient>,
pub request_id: Option<RequestId>,
pub file_storage_client: Box<dyn FileStorageInterface>,
pub encryption_client: Box<dyn EncryptionManagementInterface>,
pub file_storage_client: Arc<dyn FileStorageInterface>,
pub encryption_client: Arc<dyn EncryptionManagementInterface>,
}
impl scheduler::SchedulerAppState for AppState {
fn get_tenants(&self) -> Vec<String> {
Expand Down

0 comments on commit 88cf904

Please sign in to comment.