Skip to content

Commit 2edbd61

Browse files
feat(core): replace temp locker with redis (#2594)
1 parent c86ac9b commit 2edbd61

File tree

13 files changed

+213
-551
lines changed

13 files changed

+213
-551
lines changed

config/config.example.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ host = "" # Locker host
115115
mock_locker = true # Emulate a locker locally using Postgres
116116
basilisk_host = "" # Basilisk host
117117
locker_signing_key_id = "1" # Key_id to sign basilisk hs locker
118+
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f" # encryption key for redis temp locker
118119

119120
[delayed_session_response]
120121
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which has delayed session response

config/development.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ applepay_endpoint = "DOMAIN SPECIFIC ENDPOINT"
5050
host = ""
5151
mock_locker = true
5252
basilisk_host = ""
53+
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
5354

5455
[jwekey]
5556
locker_key_identifier1 = ""

config/docker_compose.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ recon_admin_api_key = "recon_test_admin"
4646
host = ""
4747
mock_locker = true
4848
basilisk_host = ""
49+
redis_temp_locker_encryption_key = "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
4950

5051
[jwekey]
5152
locker_key_identifier1 = ""

crates/router/src/configs/defaults.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl Default for super::settings::Locker {
5151
mock_locker: true,
5252
basilisk_host: "localhost".into(),
5353
locker_signing_key_id: "1".into(),
54+
redis_temp_locker_encryption_key: "".into(),
5455
}
5556
}
5657
}

crates/router/src/configs/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum Subcommand {
5252
#[derive(Clone)]
5353
pub struct ActiveKmsSecrets {
5454
pub jwekey: masking::Secret<Jwekey>,
55+
pub redis_temp_locker_encryption_key: masking::Secret<String>,
5556
}
5657

5758
#[derive(Debug, Deserialize, Clone, Default)]
@@ -412,6 +413,7 @@ pub struct Locker {
412413
pub mock_locker: bool,
413414
pub basilisk_host: String,
414415
pub locker_signing_key_id: String,
416+
pub redis_temp_locker_encryption_key: String,
415417
}
416418

417419
#[derive(Debug, Deserialize, Clone)]

crates/router/src/configs/validations.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ impl super::settings::Locker {
6262
"basilisk host must not be empty when mock locker is disabled".into(),
6363
))
6464
},
65+
)?;
66+
67+
when(
68+
self.redis_temp_locker_encryption_key.is_default_or_empty(),
69+
|| {
70+
Err(ApplicationError::InvalidConfigurationValueError(
71+
"redis_temp_locker_encryption_key must not be empty".into(),
72+
))
73+
},
6574
)
6675
}
6776
}

crates/router/src/core/payment_methods/cards.rs

Lines changed: 8 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,9 +2010,13 @@ pub async fn get_lookup_key_from_locker(
20102010
.change_context(errors::ApiErrorResponse::InternalServerError)
20112011
.attach_printable("Get Card Details Failed")?;
20122012
let card = card_detail.clone();
2013-
let resp =
2014-
BasiliskCardSupport::create_payment_method_data_in_locker(state, payment_token, card, pm)
2015-
.await?;
2013+
let resp = BasiliskCardSupport::create_payment_method_data_in_temp_locker(
2014+
state,
2015+
payment_token,
2016+
card,
2017+
pm,
2018+
)
2019+
.await?;
20162020
Ok(resp)
20172021
}
20182022

@@ -2060,104 +2064,9 @@ pub async fn get_lookup_key_for_payout_method(
20602064

20612065
pub struct BasiliskCardSupport;
20622066

2063-
#[cfg(not(feature = "basilisk"))]
2064-
impl BasiliskCardSupport {
2065-
async fn create_payment_method_data_in_locker(
2066-
state: &routes::AppState,
2067-
payment_token: &str,
2068-
card: api::CardDetailFromLocker,
2069-
pm: &storage::PaymentMethod,
2070-
) -> errors::RouterResult<api::CardDetailFromLocker> {
2071-
let card_number = card.card_number.clone().get_required_value("card_number")?;
2072-
let card_exp_month = card
2073-
.expiry_month
2074-
.clone()
2075-
.expose_option()
2076-
.get_required_value("expiry_month")?;
2077-
let card_exp_year = card
2078-
.expiry_year
2079-
.clone()
2080-
.expose_option()
2081-
.get_required_value("expiry_year")?;
2082-
let card_holder_name = card
2083-
.card_holder_name
2084-
.clone()
2085-
.expose_option()
2086-
.unwrap_or_default();
2087-
let value1 = payment_methods::mk_card_value1(
2088-
card_number,
2089-
card_exp_year,
2090-
card_exp_month,
2091-
Some(card_holder_name),
2092-
None,
2093-
None,
2094-
None,
2095-
)
2096-
.change_context(errors::ApiErrorResponse::InternalServerError)
2097-
.attach_printable("Error getting Value1 for locker")?;
2098-
let value2 = payment_methods::mk_card_value2(
2099-
None,
2100-
None,
2101-
None,
2102-
Some(pm.customer_id.to_string()),
2103-
Some(pm.payment_method_id.to_string()),
2104-
)
2105-
.change_context(errors::ApiErrorResponse::InternalServerError)
2106-
.attach_printable("Error getting Value2 for locker")?;
2107-
2108-
let value1 = vault::VaultPaymentMethod::Card(value1);
2109-
let value2 = vault::VaultPaymentMethod::Card(value2);
2110-
2111-
let value1 = utils::Encode::<vault::VaultPaymentMethod>::encode_to_string_of_json(&value1)
2112-
.change_context(errors::ApiErrorResponse::InternalServerError)
2113-
.attach_printable("Wrapped value1 construction failed when saving card to locker")?;
2114-
2115-
let value2 = utils::Encode::<vault::VaultPaymentMethod>::encode_to_string_of_json(&value2)
2116-
.change_context(errors::ApiErrorResponse::InternalServerError)
2117-
.attach_printable("Wrapped value2 construction failed when saving card to locker")?;
2118-
2119-
let db_value = vault::MockTokenizeDBValue { value1, value2 };
2120-
2121-
let value_string =
2122-
utils::Encode::<vault::MockTokenizeDBValue>::encode_to_string_of_json(&db_value)
2123-
.change_context(errors::ApiErrorResponse::InternalServerError)
2124-
.attach_printable(
2125-
"Mock tokenize value construction failed when saving card to locker",
2126-
)?;
2127-
2128-
let db = &*state.store;
2129-
2130-
let already_present = db.find_config_by_key(payment_token).await;
2131-
2132-
if already_present.is_err() {
2133-
let config = storage::ConfigNew {
2134-
key: payment_token.to_string(),
2135-
config: value_string,
2136-
};
2137-
2138-
db.insert_config(config)
2139-
.await
2140-
.change_context(errors::ApiErrorResponse::InternalServerError)
2141-
.attach_printable("Mock tokenization save to db failed")?;
2142-
} else {
2143-
let config_update = storage::ConfigUpdate::Update {
2144-
config: Some(value_string),
2145-
};
2146-
2147-
db.update_config_by_key(payment_token, config_update)
2148-
.await
2149-
.change_context(errors::ApiErrorResponse::InternalServerError)
2150-
.attach_printable("Mock tokenization db update failed")?;
2151-
}
2152-
2153-
Ok(card)
2154-
}
2155-
}
2156-
2157-
#[cfg(feature = "basilisk")]
21582067
impl BasiliskCardSupport {
21592068
#[instrument(skip_all)]
2160-
async fn create_payment_method_data_in_locker(
2069+
async fn create_payment_method_data_in_temp_locker(
21612070
state: &routes::AppState,
21622071
payment_token: &str,
21632072
card: api::CardDetailFromLocker,

0 commit comments

Comments
 (0)