mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
chore: drop temp_card table and all associated items (#366)
This commit is contained in:
@ -30,10 +30,9 @@ cluster_enabled = false
|
||||
use_legacy_version = false
|
||||
cluster_urls = []
|
||||
|
||||
[keys]
|
||||
temp_card_key = "OJobAzAwOlibOhygIZOqOGideGUdEBeX" # 32 character long key
|
||||
[secrets]
|
||||
admin_api_key = "test_admin"
|
||||
jwt_secret="secret"
|
||||
jwt_secret = "secret"
|
||||
|
||||
[locker]
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ pub struct Settings {
|
||||
pub replica_database: Database,
|
||||
pub redis: RedisSettings,
|
||||
pub log: Log,
|
||||
pub keys: Keys, //remove this during refactoring
|
||||
pub secrets: Secrets,
|
||||
pub locker: Locker,
|
||||
pub connectors: Connectors,
|
||||
pub refund: Refund,
|
||||
@ -51,12 +51,7 @@ pub struct Settings {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct Keys {
|
||||
#[cfg(feature = "kms")]
|
||||
pub aws_key_id: String,
|
||||
#[cfg(feature = "kms")]
|
||||
pub aws_region: String,
|
||||
pub temp_card_key: String,
|
||||
pub struct Secrets {
|
||||
pub jwt_secret: String,
|
||||
pub admin_api_key: String,
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ use error_stack::{report, ResultExt};
|
||||
use router_env::{instrument, tracing};
|
||||
|
||||
use crate::{
|
||||
configs::settings,
|
||||
core::{
|
||||
errors::{self, StorageErrorExt},
|
||||
payment_methods::transformers as payment_methods,
|
||||
@ -19,7 +18,7 @@ use crate::{
|
||||
storage::{self, enums},
|
||||
transformers::ForeignInto,
|
||||
},
|
||||
utils::{self, BytesExt, OptionExt, StringExt, ValueExt},
|
||||
utils::{BytesExt, OptionExt, StringExt},
|
||||
};
|
||||
|
||||
#[instrument(skip_all)]
|
||||
@ -789,34 +788,6 @@ impl BasiliskCardSupport {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_card_info_value(
|
||||
keys: &settings::Keys,
|
||||
card_info: String,
|
||||
) -> errors::RouterResult<serde_json::Value> {
|
||||
let key = services::KeyHandler::get_encryption_key(keys)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?;
|
||||
let enc_card_info = services::encrypt(&card_info, key.as_bytes())
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?;
|
||||
utils::Encode::<Vec<u8>>::encode_to_value(&enc_card_info)
|
||||
.change_context(errors::CardVaultError::RequestEncodingFailed)
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
}
|
||||
|
||||
pub async fn get_card_info_from_value(
|
||||
keys: &settings::Keys,
|
||||
card_info: serde_json::Value,
|
||||
) -> errors::RouterResult<String> {
|
||||
let key = services::KeyHandler::get_encryption_key(keys)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?;
|
||||
let card_info_val: Vec<u8> = card_info
|
||||
.parse_value("CardInfo")
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?;
|
||||
services::decrypt(card_info_val, key.as_bytes())
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub async fn retrieve_payment_method(
|
||||
state: &routes::AppState,
|
||||
|
||||
@ -942,36 +942,6 @@ impl Vault {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub async fn create_temp_card(
|
||||
state: &AppState,
|
||||
txn_id: &str,
|
||||
card: &api::CCard,
|
||||
) -> RouterResult<storage::TempCard> {
|
||||
let (card_info, temp_card);
|
||||
card_info = format!(
|
||||
"{}:::{}:::{}:::{}:::{}",
|
||||
card.card_number.peek(),
|
||||
card.card_exp_month.peek(),
|
||||
card.card_exp_year.peek(),
|
||||
card.card_holder_name.peek(),
|
||||
card.card_cvc.peek()
|
||||
);
|
||||
|
||||
let card_info_val = cards::get_card_info_value(&state.conf.keys, card_info).await?;
|
||||
temp_card = storage::TempCardNew {
|
||||
card_info: Some(card_info_val),
|
||||
date_created: common_utils::date_time::now(),
|
||||
txn_id: Some(txn_id.to_string()),
|
||||
id: None,
|
||||
};
|
||||
state
|
||||
.store
|
||||
.insert_temp_card(temp_card)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub(crate) fn validate_capture_method(
|
||||
capture_method: storage_enums::CaptureMethod,
|
||||
|
||||
@ -15,7 +15,6 @@ pub mod process_tracker;
|
||||
pub mod queue;
|
||||
pub mod refund;
|
||||
pub mod reverse_lookup;
|
||||
pub mod temp_card;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -39,7 +38,6 @@ pub trait StorageInterface:
|
||||
+ mandate::MandateInterface
|
||||
+ address::AddressInterface
|
||||
+ configs::ConfigInterface
|
||||
+ temp_card::TempCardInterface
|
||||
+ customers::CustomerInterface
|
||||
+ events::EventInterface
|
||||
+ merchant_account::MerchantAccountInterface
|
||||
@ -76,7 +74,6 @@ pub struct MockDb {
|
||||
payment_attempts: Arc<Mutex<Vec<storage::PaymentAttempt>>>,
|
||||
payment_intents: Arc<Mutex<Vec<storage::PaymentIntent>>>,
|
||||
customers: Arc<Mutex<Vec<storage::Customer>>>,
|
||||
temp_cards: Arc<Mutex<Vec<storage::TempCard>>>,
|
||||
refunds: Arc<Mutex<Vec<storage::Refund>>>,
|
||||
processes: Arc<Mutex<Vec<storage::ProcessTracker>>>,
|
||||
connector_response: Arc<Mutex<Vec<storage::ConnectorResponse>>>,
|
||||
@ -91,7 +88,6 @@ impl MockDb {
|
||||
payment_attempts: Default::default(),
|
||||
payment_intents: Default::default(),
|
||||
customers: Default::default(),
|
||||
temp_cards: Default::default(),
|
||||
refunds: Default::default(),
|
||||
processes: Default::default(),
|
||||
connector_response: Default::default(),
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
use error_stack::IntoReport;
|
||||
|
||||
use super::{MockDb, Store};
|
||||
use crate::{
|
||||
connection::pg_connection,
|
||||
core::errors::{self, CustomResult},
|
||||
types::storage,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait TempCardInterface {
|
||||
async fn find_tempcard_by_token(
|
||||
&self,
|
||||
token: &i32,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError>;
|
||||
|
||||
async fn insert_temp_card(
|
||||
&self,
|
||||
address: storage::TempCardNew,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError>;
|
||||
|
||||
async fn find_tempcard_by_transaction_id(
|
||||
&self,
|
||||
transaction_id: &str,
|
||||
) -> CustomResult<Option<storage::TempCard>, errors::StorageError>;
|
||||
|
||||
async fn insert_tempcard_with_token(
|
||||
&self,
|
||||
new: storage::TempCard,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl TempCardInterface for Store {
|
||||
async fn insert_temp_card(
|
||||
&self,
|
||||
address: storage::TempCardNew,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
let conn = pg_connection(&self.master_pool).await;
|
||||
address
|
||||
.insert(&conn)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn find_tempcard_by_transaction_id(
|
||||
&self,
|
||||
transaction_id: &str,
|
||||
) -> CustomResult<Option<storage::TempCard>, errors::StorageError> {
|
||||
let conn = pg_connection(&self.master_pool).await;
|
||||
storage::TempCard::find_by_transaction_id(&conn, transaction_id)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn insert_tempcard_with_token(
|
||||
&self,
|
||||
card: storage::TempCard,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
let conn = pg_connection(&self.master_pool).await;
|
||||
storage::TempCard::insert_with_token(card, &conn)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn find_tempcard_by_token(
|
||||
&self,
|
||||
token: &i32,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
let conn = pg_connection(&self.master_pool).await;
|
||||
storage::TempCard::find_by_token(&conn, token)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl TempCardInterface for MockDb {
|
||||
#[allow(clippy::panic)]
|
||||
async fn insert_temp_card(
|
||||
&self,
|
||||
insert: storage::TempCardNew,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
let mut cards = self.temp_cards.lock().await;
|
||||
let card = storage::TempCard {
|
||||
#[allow(clippy::as_conversions)]
|
||||
id: cards.len() as i32,
|
||||
date_created: insert.date_created,
|
||||
txn_id: insert.txn_id,
|
||||
card_info: insert.card_info,
|
||||
};
|
||||
cards.push(card.clone());
|
||||
Ok(card)
|
||||
}
|
||||
|
||||
async fn find_tempcard_by_transaction_id(
|
||||
&self,
|
||||
_transaction_id: &str,
|
||||
) -> CustomResult<Option<storage::TempCard>, errors::StorageError> {
|
||||
// [#172]: Implement function for `MockDb`
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn insert_tempcard_with_token(
|
||||
&self,
|
||||
_card: storage::TempCard,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
// [#172]: Implement function for `MockDb`
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn find_tempcard_by_token(
|
||||
&self,
|
||||
_token: &i32,
|
||||
) -> CustomResult<storage::TempCard, errors::StorageError> {
|
||||
// [#172]: Implement function for `MockDb`
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ impl AuthenticateAndFetch<()> for AdminApiAuth {
|
||||
) -> RouterResult<()> {
|
||||
let admin_api_key =
|
||||
get_api_key(request_headers).change_context(errors::ApiErrorResponse::Unauthorized)?;
|
||||
if admin_api_key != state.conf.keys.admin_api_key {
|
||||
if admin_api_key != state.conf.secrets.admin_api_key {
|
||||
Err(report!(errors::ApiErrorResponse::Unauthorized)
|
||||
.attach_printable("Admin Authentication Failure"))?;
|
||||
}
|
||||
@ -231,7 +231,7 @@ pub fn decode_jwt<T>(token: &str, state: &AppState) -> RouterResult<T>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
let secret = state.conf.keys.jwt_secret.as_bytes();
|
||||
let secret = state.conf.secrets.jwt_secret.as_bytes();
|
||||
let key = DecodingKey::from_secret(secret);
|
||||
decode::<T>(token, &key, &Validation::new(Algorithm::HS256))
|
||||
.map(|decoded| decoded.claims)
|
||||
|
||||
@ -6,7 +6,7 @@ use rand;
|
||||
use ring::{aead::*, error::Unspecified};
|
||||
|
||||
use crate::{
|
||||
configs::settings::{Jwekey, Keys},
|
||||
configs::settings::Jwekey,
|
||||
core::errors::{self, CustomResult},
|
||||
utils,
|
||||
};
|
||||
@ -102,86 +102,11 @@ mod kms {
|
||||
.attach_printable("Missing plaintext in response")),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_encryption_key(
|
||||
keys: &Keys,
|
||||
) -> CustomResult<String, errors::EncryptionError> {
|
||||
let kms_enc_key = keys.temp_card_key.to_string();
|
||||
let region = keys.aws_region.to_string();
|
||||
let key_id = keys.aws_key_id.clone();
|
||||
let region_provider = RegionProviderChain::first_try(Region::new(region));
|
||||
let shared_config = aws_config::from_env().region(region_provider).load().await;
|
||||
let client = Client::new(&shared_config);
|
||||
let data = consts::BASE64_ENGINE
|
||||
.decode(kms_enc_key)
|
||||
.into_report()
|
||||
.change_context(errors::EncryptionError)
|
||||
.attach_printable("Error decoding from base64")?;
|
||||
let blob = Blob::new(data);
|
||||
let resp = client
|
||||
.decrypt()
|
||||
.key_id(key_id)
|
||||
.ciphertext_blob(blob)
|
||||
.send()
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(errors::EncryptionError)
|
||||
.attach_printable("Error decrypting kms encrypted data")?;
|
||||
match resp.plaintext() {
|
||||
Some(inner) => {
|
||||
let bytes = inner.as_ref().to_vec();
|
||||
let res = String::from_utf8(bytes)
|
||||
.into_report()
|
||||
.change_context(errors::EncryptionError)
|
||||
.attach_printable("Could not convert to UTF-8")?;
|
||||
Ok(res)
|
||||
}
|
||||
None => Err(report!(errors::EncryptionError)
|
||||
.attach_printable("Missing plaintext in response")),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_encryption_key(
|
||||
input: &str,
|
||||
keys: &Keys,
|
||||
) -> CustomResult<String, errors::EncryptionError> {
|
||||
let region = keys.aws_region.to_string();
|
||||
let key_id = keys.aws_key_id.clone();
|
||||
let region_provider = RegionProviderChain::first_try(Region::new(region));
|
||||
let shared_config = aws_config::from_env().region(region_provider).load().await;
|
||||
let client = Client::new(&shared_config);
|
||||
let blob = Blob::new(input.as_bytes());
|
||||
let resp = client
|
||||
.encrypt()
|
||||
.key_id(key_id)
|
||||
.plaintext(blob)
|
||||
.send()
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(errors::EncryptionError)
|
||||
.attach_printable("Error getting EncryptOutput")?;
|
||||
match resp.ciphertext_blob {
|
||||
Some(blob) => {
|
||||
let bytes = blob.as_ref();
|
||||
let encoded_res = consts::BASE64_ENGINE.encode(bytes);
|
||||
Ok(encoded_res)
|
||||
}
|
||||
None => {
|
||||
Err(report!(errors::EncryptionError)
|
||||
.attach_printable("Missing ciphertext blob"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "kms"))]
|
||||
impl KeyHandler {
|
||||
// Fetching KMS decrypted key
|
||||
pub async fn get_encryption_key(keys: &Keys) -> CustomResult<String, errors::EncryptionError> {
|
||||
Ok(keys.temp_card_key.clone())
|
||||
}
|
||||
|
||||
pub async fn get_kms_decrypted_key(
|
||||
_aws_keys: &Jwekey,
|
||||
key: String,
|
||||
@ -337,20 +262,6 @@ mod tests {
|
||||
assert_eq!(dec_data, "Test_Encrypt".to_string());
|
||||
}
|
||||
|
||||
#[cfg(feature = "kms")]
|
||||
#[actix_rt::test]
|
||||
#[ignore]
|
||||
async fn test_kms() {
|
||||
let conf = settings::Settings::new().unwrap();
|
||||
let kms_encrypted = KeyHandler::get_encryption_key(&conf.keys)
|
||||
.await
|
||||
.expect("Error encode_kms");
|
||||
let kms_decrypted = KeyHandler::set_encryption_key(&kms_encrypted, &conf.keys)
|
||||
.await
|
||||
.expect("error decode_kms");
|
||||
assert_eq!("Testing KMS".to_string(), kms_decrypted)
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_jwe() {
|
||||
let conf = settings::Settings::new().unwrap();
|
||||
|
||||
@ -17,7 +17,6 @@ pub mod reverse_lookup;
|
||||
|
||||
mod query;
|
||||
pub mod refund;
|
||||
pub mod temp_card;
|
||||
|
||||
#[cfg(feature = "kv_store")]
|
||||
pub mod kv;
|
||||
@ -26,5 +25,4 @@ pub use self::{
|
||||
address::*, configs::*, connector_response::*, customers::*, events::*, locker_mock_up::*,
|
||||
mandate::*, merchant_account::*, merchant_connector_account::*, payment_attempt::*,
|
||||
payment_intent::*, payment_method::*, process_tracker::*, refund::*, reverse_lookup::*,
|
||||
temp_card::*,
|
||||
};
|
||||
|
||||
@ -1 +0,0 @@
|
||||
pub use storage_models::temp_card::{TempCard, TempCardNew};
|
||||
Reference in New Issue
Block a user