pub mod address; pub mod api_keys; pub mod business_profile; pub mod cache; pub mod capture; pub mod cards_info; pub mod configs; pub mod connector_response; pub mod customers; pub mod dispute; pub mod ephemeral_key; pub mod events; pub mod file; pub mod fraud_check; pub mod locker_mock_up; pub mod mandate; pub mod merchant_account; pub mod merchant_connector_account; pub mod merchant_key_store; pub mod payment_method; pub mod payout_attempt; pub mod payouts; pub mod refund; pub mod reverse_lookup; use data_models::payments::{ payment_attempt::PaymentAttemptInterface, payment_intent::PaymentIntentInterface, }; use masking::PeekInterface; use storage_impl::{redis::kv_store::RedisConnInterface, MockDb}; use crate::services::Store; #[derive(PartialEq, Eq)] pub enum StorageImpl { Postgresql, PostgresqlTest, Mock, } #[async_trait::async_trait] pub trait StorageInterface: Send + Sync + dyn_clone::DynClone + address::AddressInterface + api_keys::ApiKeyInterface + configs::ConfigInterface + capture::CaptureInterface + connector_response::ConnectorResponseInterface + customers::CustomerInterface + dispute::DisputeInterface + ephemeral_key::EphemeralKeyInterface + events::EventInterface + file::FileMetadataInterface + fraud_check::FraudCheckInterface + locker_mock_up::LockerMockUpInterface + mandate::MandateInterface + merchant_account::MerchantAccountInterface + merchant_connector_account::ConnectorAccessToken + merchant_connector_account::MerchantConnectorAccountInterface + PaymentAttemptInterface + PaymentIntentInterface + payment_method::PaymentMethodInterface + scheduler::SchedulerInterface + payout_attempt::PayoutAttemptInterface + payouts::PayoutsInterface + refund::RefundInterface + reverse_lookup::ReverseLookupInterface + cards_info::CardsInfoInterface + merchant_key_store::MerchantKeyStoreInterface + MasterKeyInterface + RedisConnInterface + business_profile::BusinessProfileInterface + 'static { fn get_scheduler_db(&self) -> Box; } pub trait MasterKeyInterface { fn get_master_key(&self) -> &[u8]; } impl MasterKeyInterface for Store { fn get_master_key(&self) -> &[u8] { self.master_key().peek() } } /// Default dummy key for MockDb impl MasterKeyInterface for MockDb { fn get_master_key(&self) -> &[u8] { &[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ] } } #[async_trait::async_trait] impl StorageInterface for Store { fn get_scheduler_db(&self) -> Box { Box::new(self.clone()) } } #[async_trait::async_trait] impl StorageInterface for MockDb { fn get_scheduler_db(&self) -> Box { Box::new(self.clone()) } } pub async fn get_and_deserialize_key( db: &dyn StorageInterface, key: &str, type_name: &'static str, ) -> common_utils::errors::CustomResult where T: serde::de::DeserializeOwned, { use common_utils::ext_traits::ByteSliceExt; use error_stack::ResultExt; let bytes = db.get_key(key).await?; bytes .parse_struct(type_name) .change_context(redis_interface::errors::RedisError::JsonDeserializationFailed) } dyn_clone::clone_trait_object!(StorageInterface);