mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
refactor: rename kms feature flag to aws_kms (#3249)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
42
crates/external_services/src/aws_kms/decrypt.rs
Normal file
42
crates/external_services/src/aws_kms/decrypt.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use common_utils::errors::CustomResult;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
/// This trait performs in place decryption of the structure on which this is implemented
|
||||
pub trait AwsKmsDecrypt {
|
||||
/// The output type of the decryption
|
||||
type Output;
|
||||
/// Decrypts the structure given a AWS KMS client
|
||||
async fn decrypt_inner(
|
||||
self,
|
||||
aws_kms_client: &AwsKmsClient,
|
||||
) -> CustomResult<Self::Output, AwsKmsError>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
/// Tries to use the Singleton client to decrypt the structure
|
||||
async fn try_decrypt_inner(self) -> CustomResult<Self::Output, AwsKmsError>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let client = AWS_KMS_CLIENT
|
||||
.get()
|
||||
.ok_or(AwsKmsError::AwsKmsClientNotInitialized)?;
|
||||
self.decrypt_inner(client).await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AwsKmsDecrypt for &AwsKmsValue {
|
||||
type Output = String;
|
||||
async fn decrypt_inner(
|
||||
self,
|
||||
aws_kms_client: &AwsKmsClient,
|
||||
) -> CustomResult<Self::Output, AwsKmsError> {
|
||||
aws_kms_client
|
||||
.decrypt(self.0.peek())
|
||||
.await
|
||||
.attach_printable("Failed to decrypt AWS KMS value")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user