refactor(router): remove fallback feature for /add and /get for locker (#3648)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Shankar Singh C
2024-02-19 12:38:04 +05:30
committed by GitHub
parent 646e11739d
commit d0f529fa4b
9 changed files with 31 additions and 161 deletions

View File

@ -502,8 +502,7 @@ pub enum RetryAction {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum LockerChoice { pub enum LockerChoice {
Basilisk, HyperswitchCardVault,
Tartarus,
} }
#[derive( #[derive(

View File

@ -126,7 +126,7 @@ pub async fn call_to_locker(
&card_details, &card_details,
customer_id.to_string(), customer_id.to_string(),
merchant_account, merchant_account,
api_enums::LockerChoice::Tartarus, api_enums::LockerChoice::HyperswitchCardVault,
Some(&pm.payment_method_id), Some(&pm.payment_method_id),
) )
.await .await

View File

@ -225,7 +225,7 @@ pub async fn add_payment_method(
&card, &card,
customer_id.clone(), customer_id.clone(),
merchant_account, merchant_account,
api::enums::LockerChoice::Tartarus, api::enums::LockerChoice::HyperswitchCardVault,
Some(&resp.payment_method_id), Some(&resp.payment_method_id),
) )
.await; .await;
@ -454,7 +454,7 @@ pub async fn add_bank_to_locker(
state, state,
&payload, &payload,
customer_id, customer_id,
api_enums::LockerChoice::Basilisk, api_enums::LockerChoice::HyperswitchCardVault,
) )
.await?; .await?;
let payment_method_resp = payment_methods::mk_add_bank_response_hs( let payment_method_resp = payment_methods::mk_add_bank_response_hs(
@ -489,42 +489,10 @@ pub async fn add_card_to_locker(
card, card,
customer_id.to_string(), customer_id.to_string(),
merchant_account, merchant_account,
api_enums::LockerChoice::Basilisk, api_enums::LockerChoice::HyperswitchCardVault,
None, None,
) )
.await .await
.map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "basilisk"),
router_env::opentelemetry::KeyValue::new("operation", "add"),
],
);
error
})
},
&metrics::CARD_ADD_TIME,
&[router_env::opentelemetry::KeyValue::new(
"locker", "basilisk",
)],
)
.await?;
logger::debug!("card added to basilisk locker");
let add_card_to_rs_resp = request::record_operation_time(
async {
add_card_hs(
state,
req,
card,
customer_id.to_string(),
merchant_account,
api_enums::LockerChoice::Tartarus,
Some(&add_card_to_hs_resp.0.payment_method_id),
)
.await
.map_err(|error| { .map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add( metrics::CARD_LOCKER_FAILURES.add(
&metrics::CONTEXT, &metrics::CONTEXT,
@ -540,34 +508,10 @@ pub async fn add_card_to_locker(
&metrics::CARD_ADD_TIME, &metrics::CARD_ADD_TIME,
&[router_env::opentelemetry::KeyValue::new("locker", "rust")], &[router_env::opentelemetry::KeyValue::new("locker", "rust")],
) )
.await; .await?;
match add_card_to_rs_resp { logger::debug!("card added to hyperswitch-card-vault");
value @ Ok(_) => { Ok(add_card_to_hs_resp)
logger::debug!("card added to rust locker");
let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "rust"),
router_env::opentelemetry::KeyValue::new("operation", "add"),
],
);
value
}
Err(err) => {
logger::debug!(error =? err,"failed to add card to rust locker");
let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "basilisk"),
router_env::opentelemetry::KeyValue::new("operation", "add"),
],
);
Ok(add_card_to_hs_resp)
}
}
} }
pub async fn get_card_from_locker( pub async fn get_card_from_locker(
@ -585,11 +529,11 @@ pub async fn get_card_from_locker(
customer_id, customer_id,
merchant_id, merchant_id,
card_reference, card_reference,
api_enums::LockerChoice::Tartarus, api_enums::LockerChoice::HyperswitchCardVault,
) )
.await .await
.change_context(errors::ApiErrorResponse::InternalServerError) .change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while getting card from basilisk_hs") .attach_printable("Failed while getting card from hyperswitch card vault")
.map_err(|error| { .map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add( metrics::CARD_LOCKER_FAILURES.add(
&metrics::CONTEXT, &metrics::CONTEXT,
@ -605,64 +549,10 @@ pub async fn get_card_from_locker(
&metrics::CARD_GET_TIME, &metrics::CARD_GET_TIME,
&[router_env::opentelemetry::KeyValue::new("locker", "rust")], &[router_env::opentelemetry::KeyValue::new("locker", "rust")],
) )
.await; .await?;
match get_card_from_rs_locker_resp { logger::debug!("card retrieved from rust locker");
Err(_) => request::record_operation_time( Ok(get_card_from_rs_locker_resp)
async {
get_card_from_hs_locker(
state,
customer_id,
merchant_id,
card_reference,
api_enums::LockerChoice::Basilisk,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while getting card from basilisk_hs")
.map_err(|error| {
metrics::CARD_LOCKER_FAILURES.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "basilisk"),
router_env::opentelemetry::KeyValue::new("operation", "get"),
],
);
error
})
},
&metrics::CARD_GET_TIME,
&[router_env::opentelemetry::KeyValue::new(
"locker", "basilisk",
)],
)
.await
.map(|inner_card| {
logger::debug!("card retrieved from basilisk locker");
let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "basilisk"),
router_env::opentelemetry::KeyValue::new("operation", "get"),
],
);
inner_card
}),
Ok(_) => {
logger::debug!("card retrieved from rust locker");
let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(
&metrics::CONTEXT,
1,
&[
router_env::opentelemetry::KeyValue::new("locker", "rust"),
router_env::opentelemetry::KeyValue::new("operation", "get"),
],
);
get_card_from_rs_locker_resp
}
}
} }
pub async fn delete_card_from_locker( pub async fn delete_card_from_locker(
@ -967,7 +857,7 @@ pub async fn delete_card_from_hs_locker<'a>(
let decrypted_payload = payment_methods::get_decrypted_response_payload( let decrypted_payload = payment_methods::get_decrypted_response_payload(
jwekey, jwekey,
jwe_body, jwe_body,
Some(api_enums::LockerChoice::Basilisk), Some(api_enums::LockerChoice::HyperswitchCardVault),
) )
.await .await
.change_context(errors::ApiErrorResponse::InternalServerError) .change_context(errors::ApiErrorResponse::InternalServerError)

View File

@ -198,13 +198,12 @@ pub async fn get_decrypted_response_payload(
jwe_body: encryption::JweBody, jwe_body: encryption::JweBody,
locker_choice: Option<api_enums::LockerChoice>, locker_choice: Option<api_enums::LockerChoice>,
) -> CustomResult<String, errors::VaultError> { ) -> CustomResult<String, errors::VaultError> {
let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::Basilisk); let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);
#[cfg(feature = "aws_kms")] #[cfg(feature = "aws_kms")]
let public_key = match target_locker { let public_key = match target_locker {
api_enums::LockerChoice::Basilisk => jwekey.jwekey.peek().vault_encryption_key.as_bytes(), api_enums::LockerChoice::HyperswitchCardVault => {
api_enums::LockerChoice::Tartarus => { jwekey.jwekey.peek().vault_encryption_key.as_bytes()
jwekey.jwekey.peek().rust_locker_encryption_key.as_bytes()
} }
}; };
@ -213,8 +212,7 @@ pub async fn get_decrypted_response_payload(
#[cfg(not(feature = "aws_kms"))] #[cfg(not(feature = "aws_kms"))]
let public_key = match target_locker { let public_key = match target_locker {
api_enums::LockerChoice::Basilisk => jwekey.vault_encryption_key.as_bytes(), api_enums::LockerChoice::HyperswitchCardVault => jwekey.vault_encryption_key.as_bytes(),
api_enums::LockerChoice::Tartarus => jwekey.rust_locker_encryption_key.as_bytes(),
}; };
#[cfg(not(feature = "aws_kms"))] #[cfg(not(feature = "aws_kms"))]
@ -266,16 +264,14 @@ pub async fn mk_basilisk_req(
#[cfg(feature = "aws_kms")] #[cfg(feature = "aws_kms")]
let public_key = match locker_choice { let public_key = match locker_choice {
api_enums::LockerChoice::Basilisk => jwekey.jwekey.peek().vault_encryption_key.as_bytes(), api_enums::LockerChoice::HyperswitchCardVault => {
api_enums::LockerChoice::Tartarus => { jwekey.jwekey.peek().vault_encryption_key.as_bytes()
jwekey.jwekey.peek().rust_locker_encryption_key.as_bytes()
} }
}; };
#[cfg(not(feature = "aws_kms"))] #[cfg(not(feature = "aws_kms"))]
let public_key = match locker_choice { let public_key = match locker_choice {
api_enums::LockerChoice::Basilisk => jwekey.vault_encryption_key.as_bytes(), api_enums::LockerChoice::HyperswitchCardVault => jwekey.vault_encryption_key.as_bytes(),
api_enums::LockerChoice::Tartarus => jwekey.rust_locker_encryption_key.as_bytes(),
}; };
let jwe_encrypted = encryption::encrypt_jwe(&payload, public_key) let jwe_encrypted = encryption::encrypt_jwe(&payload, public_key)
@ -321,8 +317,7 @@ pub async fn mk_add_locker_request_hs<'a>(
let jwe_payload = mk_basilisk_req(jwekey, &jws, locker_choice).await?; let jwe_payload = mk_basilisk_req(jwekey, &jws, locker_choice).await?;
let mut url = match locker_choice { let mut url = match locker_choice {
api_enums::LockerChoice::Basilisk => locker.host.to_owned(), api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),
api_enums::LockerChoice::Tartarus => locker.host_rs.to_owned(),
}; };
url.push_str("/cards/add"); url.push_str("/cards/add");
let mut request = services::Request::new(services::Method::Post, &url); let mut request = services::Request::new(services::Method::Post, &url);
@ -497,12 +492,11 @@ pub async fn mk_get_card_request_hs(
.await .await
.change_context(errors::VaultError::RequestEncodingFailed)?; .change_context(errors::VaultError::RequestEncodingFailed)?;
let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::Basilisk); let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);
let jwe_payload = mk_basilisk_req(jwekey, &jws, target_locker).await?; let jwe_payload = mk_basilisk_req(jwekey, &jws, target_locker).await?;
let mut url = match target_locker { let mut url = match target_locker {
api_enums::LockerChoice::Basilisk => locker.host.to_owned(), api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),
api_enums::LockerChoice::Tartarus => locker.host_rs.to_owned(),
}; };
url.push_str("/cards/retrieve"); url.push_str("/cards/retrieve");
let mut request = services::Request::new(services::Method::Post, &url); let mut request = services::Request::new(services::Method::Post, &url);
@ -573,7 +567,8 @@ pub async fn mk_delete_card_request_hs(
.await .await
.change_context(errors::VaultError::RequestEncodingFailed)?; .change_context(errors::VaultError::RequestEncodingFailed)?;
let jwe_payload = mk_basilisk_req(jwekey, &jws, api_enums::LockerChoice::Basilisk).await?; let jwe_payload =
mk_basilisk_req(jwekey, &jws, api_enums::LockerChoice::HyperswitchCardVault).await?;
let mut url = locker.host.to_owned(); let mut url = locker.host.to_owned();
url.push_str("/cards/delete"); url.push_str("/cards/delete");

View File

@ -179,7 +179,7 @@ where
&card, &card,
customer.customer_id.clone(), customer.customer_id.clone(),
merchant_account, merchant_account,
api::enums::LockerChoice::Tartarus, api::enums::LockerChoice::HyperswitchCardVault,
Some(&locker_response.0.payment_method_id), Some(&locker_response.0.payment_method_id),
) )
.await; .await;

View File

@ -267,7 +267,7 @@ pub async fn save_payout_data_to_locker(
state, state,
&locker_req, &locker_req,
&payout_attempt.customer_id, &payout_attempt.customer_id,
api_enums::LockerChoice::Basilisk, api_enums::LockerChoice::HyperswitchCardVault,
) )
.await .await
.change_context(errors::ApiErrorResponse::InternalServerError)?; .change_context(errors::ApiErrorResponse::InternalServerError)?;

View File

@ -135,7 +135,6 @@ pub fn mk_app(
.service(routes::Analytics::server(state.clone())) .service(routes::Analytics::server(state.clone()))
.service(routes::Routing::server(state.clone())) .service(routes::Routing::server(state.clone()))
.service(routes::Blocklist::server(state.clone())) .service(routes::Blocklist::server(state.clone()))
.service(routes::LockerMigrate::server(state.clone()))
.service(routes::Gsm::server(state.clone())) .service(routes::Gsm::server(state.clone()))
.service(routes::PaymentLink::server(state.clone())) .service(routes::PaymentLink::server(state.clone()))
.service(routes::User::server(state.clone())) .service(routes::User::server(state.clone()))

View File

@ -61,7 +61,7 @@ pub use self::app::Recon;
pub use self::app::Verify; pub use self::app::Verify;
pub use self::app::{ pub use self::app::{
ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers, ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers,
Disputes, EphemeralKey, Files, Gsm, Health, LockerMigrate, Mandates, MerchantAccount, Disputes, EphemeralKey, Files, Gsm, Health, Mandates, MerchantAccount,
MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks, MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks,
}; };
#[cfg(feature = "stripe")] #[cfg(feature = "stripe")]

View File

@ -37,8 +37,8 @@ use super::routing as cloud_routing;
use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains}; use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};
#[cfg(feature = "olap")] #[cfg(feature = "olap")]
use super::{ use super::{
admin::*, api_keys::*, connector_onboarding::*, disputes::*, files::*, gsm::*, admin::*, api_keys::*, connector_onboarding::*, disputes::*, files::*, gsm::*, payment_link::*,
locker_migration, payment_link::*, user::*, user_role::*, user::*, user_role::*,
}; };
use super::{cache::*, health::*}; use super::{cache::*, health::*};
#[cfg(any(feature = "olap", feature = "oltp"))] #[cfg(any(feature = "olap", feature = "oltp"))]
@ -1064,19 +1064,6 @@ impl User {
} }
} }
pub struct LockerMigrate;
#[cfg(feature = "olap")]
impl LockerMigrate {
pub fn server(state: AppState) -> Scope {
web::scope("locker_migration/{merchant_id}")
.app_data(web::Data::new(state))
.service(
web::resource("").route(web::post().to(locker_migration::rust_locker_migration)),
)
}
}
pub struct ConnectorOnboarding; pub struct ConnectorOnboarding;
#[cfg(feature = "olap")] #[cfg(feature = "olap")]