Skip to content

Commit

Permalink
refactor: resolve comments (part1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakilmostak committed Feb 2, 2025
1 parent 252c225 commit 20386bd
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 91 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3651,21 +3651,7 @@ pub enum FeatureStatus {
Supported,
}

#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
Hash,
strum::Display,
strum::VariantNames,
strum::EnumIter,
strum::EnumString,
Deserialize,
Serialize,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GooglePayAuthMethod {
/// Contain pan data only
Expand Down
1 change: 1 addition & 0 deletions crates/common_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ payment_methods_v2 = []
[dependencies]
async-trait = { version = "0.1.79", optional = true }
base64 = "0.22.0"
base64-serde = "0.8.0"
blake3 = { version = "1.5.1", features = ["serde"] }
bytes = "1.6.0"
diesel = "2.2.3"
Expand Down
16 changes: 14 additions & 2 deletions crates/common_utils/src/custom_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,20 @@ pub mod timestamp {

/// <https://github.com/serde-rs/serde/issues/994#issuecomment-316895860>
pub mod json_string {
use serde::de::{self, Deserialize, DeserializeOwned, Deserializer};
use serde_json;
use serde::{
de::{self, Deserialize, DeserializeOwned, Deserializer},
ser::{self, Serialize, Serializer},
};

/// Serialize a type to json_string format
pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: Serialize,
S: Serializer,
{
let j = serde_json::to_string(value).map_err(ser::Error::custom)?;
j.serialize(serializer)
}

/// Deserialize a string which is in json format
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<T, D::Error>
Expand Down
10 changes: 10 additions & 0 deletions crates/common_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub mod hashing;
#[cfg(feature = "metrics")]
pub mod metrics;

pub use base64_serializer::Base64Serializer;

/// Date-time utilities.
pub mod date_time {
#[cfg(feature = "async_ext")]
Expand Down Expand Up @@ -296,6 +298,14 @@ pub trait DbConnectionParams {
}
}

// Can't add doc comments for macro invocations, neither does the macro allow it.
#[allow(missing_docs)]
mod base64_serializer {
use base64_serde::base64_serde_type;

base64_serde_type!(pub Base64Serializer, crate::consts::BASE64_ENGINE);
}

#[cfg(test)]
mod nanoid_tests {
#![allow(clippy::unwrap_used)]
Expand Down
7 changes: 7 additions & 0 deletions crates/masking/src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ where
SecretValue::default().into()
}
}

// Required by base64-serde to serialize Secret
impl<T> AsRef<[T]> for Secret<Vec<T>> {
fn as_ref(&self) -> &[T] {
self.peek().as_slice()
}
}
7 changes: 6 additions & 1 deletion crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ pub struct PazeDecryptConfig {
pub paze_private_key_passphrase: Secret<String>,
}

#[derive(Debug, Deserialize, Clone, Default)]
#[derive(Debug, Deserialize, Clone)]
pub struct GooglePayDecryptConfig {
pub google_pay_root_signing_keys: Secret<String>,
}
Expand Down Expand Up @@ -917,6 +917,11 @@ impl Settings<SecuredSecret> {
.map(|x| x.get_inner().validate())
.transpose()?;

self.google_pay_decrypt_keys
.as_ref()
.map(|x| x.get_inner().validate())
.transpose()?;

self.key_manager.get_inner().validate()?;
#[cfg(feature = "email")]
self.email
Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/configs/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ impl super::settings::PazeDecryptConfig {
}
}

impl super::settings::GooglePayDecryptConfig {
pub fn validate(&self) -> Result<(), ApplicationError> {
use common_utils::fp_utils::when;

when(
self.google_pay_root_signing_keys.is_default_or_empty(),
|| {
Err(ApplicationError::InvalidConfigurationValueError(
"google_pay_root_signing_keys must not be empty".into(),
))
},
)
}
}

impl super::settings::KeyManagerConfig {
pub fn validate(&self) -> Result<(), ApplicationError> {
use common_utils::fp_utils::when;
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/core/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ pub enum PazeDecryptionError {
pub enum GooglePayDecryptionError {
#[error("Recipient ID not found")]
RecipientIdNotFound,
#[error("Failed to fetch time delta for expiration")]
SystemTimeError,
#[error("Invalid expiration time")]
InvalidExpirationTime,
#[error("Failed to base64 decode input data")]
Base64DecodingFailed,
#[error("Failed to decrypt input data")]
Expand Down
Loading

0 comments on commit 20386bd

Please sign in to comment.