diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index efde4a048323..6bb4fd4afa0f 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use common_utils::{ crypto::{Encryptable, OptionalEncryptableName}, pii, @@ -614,6 +616,36 @@ pub struct MerchantConnectorCreate { pub status: Option, } +// Different patterns of authentication. +#[derive(Default, Debug, Clone, serde::Deserialize, serde::Serialize)] +#[serde(tag = "auth_type")] +pub enum ConnectorAuthType { + TemporaryAuth, + HeaderKey { + api_key: Secret, + }, + BodyKey { + api_key: Secret, + key1: Secret, + }, + SignatureKey { + api_key: Secret, + key1: Secret, + api_secret: Secret, + }, + MultiAuthKey { + api_key: Secret, + key1: Secret, + api_secret: Secret, + key2: Secret, + }, + CurrencyAuthKey { + auth_key_map: HashMap, + }, + #[default] + NoKey, +} + #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] #[serde(deny_unknown_fields)] pub struct MerchantConnectorWebhookDetails { diff --git a/crates/api_models/src/lib.rs b/crates/api_models/src/lib.rs index 1abeff7b6ddb..767860248c48 100644 --- a/crates/api_models/src/lib.rs +++ b/crates/api_models/src/lib.rs @@ -26,4 +26,5 @@ pub mod routing; pub mod surcharge_decision_configs; pub mod user; pub mod verifications; +pub mod verify_connector; pub mod webhooks; diff --git a/crates/api_models/src/verify_connector.rs b/crates/api_models/src/verify_connector.rs new file mode 100644 index 000000000000..1db5a19a030a --- /dev/null +++ b/crates/api_models/src/verify_connector.rs @@ -0,0 +1,11 @@ +use common_utils::events::{ApiEventMetric, ApiEventsType}; + +use crate::{admin, enums}; + +#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +pub struct VerifyConnectorRequest { + pub connector_name: enums::Connector, + pub connector_account_details: admin::ConnectorAuthType, +} + +common_utils::impl_misc_api_event_type!(VerifyConnectorRequest); diff --git a/crates/kgraph_utils/src/mca.rs b/crates/kgraph_utils/src/mca.rs index deea51bd8808..a7f07be7dac1 100644 --- a/crates/kgraph_utils/src/mca.rs +++ b/crates/kgraph_utils/src/mca.rs @@ -362,7 +362,7 @@ mod tests { connector_label: Some("something".to_string()), business_label: Some("food".to_string()), business_sub_label: None, - connector_account_details: masking::Secret::new(serde_json::json!({})), + connector_account_details: ConnectorAuthType::default(), test_mode: None, disabled: None, metadata: None, diff --git a/crates/router/src/core/verify_connector.rs b/crates/router/src/core/verify_connector.rs index 10e2297d4a08..e837e8b8b259 100644 --- a/crates/router/src/core/verify_connector.rs +++ b/crates/router/src/core/verify_connector.rs @@ -1,4 +1,4 @@ -use api_models::enums::Connector; +use api_models::{enums::Connector, verify_connector::VerifyConnectorRequest}; use error_stack::{IntoReport, ResultExt}; use crate::{ @@ -15,7 +15,7 @@ use crate::{ pub async fn verify_connector_credentials( state: AppState, - req: types::VerifyConnectorRequest, + req: VerifyConnectorRequest, ) -> errors::RouterResponse<()> { let boxed_connector = api::ConnectorData::get_connector_by_name( &state.conf.connectors, @@ -38,7 +38,7 @@ pub async fn verify_connector_credentials( &state, types::VerifyConnectorData { connector: *boxed_connector.connector, - connector_auth: req.connector_account_details, + connector_auth: req.connector_account_details.into(), card_details, }, ) @@ -48,7 +48,7 @@ pub async fn verify_connector_credentials( &state, types::VerifyConnectorData { connector: *boxed_connector.connector, - connector_auth: req.connector_account_details, + connector_auth: req.connector_account_details.into(), card_details, }, ) diff --git a/crates/router/src/routes/verify_connector.rs b/crates/router/src/routes/verify_connector.rs index 28128050e5a4..bfb1b781ada4 100644 --- a/crates/router/src/routes/verify_connector.rs +++ b/crates/router/src/routes/verify_connector.rs @@ -1,11 +1,11 @@ use actix_web::{web, HttpRequest, HttpResponse}; +use api_models::verify_connector::VerifyConnectorRequest; use router_env::{instrument, tracing, Flow}; use super::AppState; use crate::{ core::{api_locking, verify_connector}, services::{self, authentication as auth, authorization::permissions::Permission}, - types::api::verify_connector::VerifyConnectorRequest, }; #[instrument(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 8c9d030965c9..a179dba1f73c 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -941,6 +941,82 @@ pub enum ConnectorAuthType { NoKey, } +impl From for ConnectorAuthType { + fn from(value: api_models::admin::ConnectorAuthType) -> Self { + match value { + api_models::admin::ConnectorAuthType::TemporaryAuth => Self::TemporaryAuth, + api_models::admin::ConnectorAuthType::HeaderKey { api_key } => { + Self::HeaderKey { api_key } + } + api_models::admin::ConnectorAuthType::BodyKey { api_key, key1 } => { + Self::BodyKey { api_key, key1 } + } + api_models::admin::ConnectorAuthType::SignatureKey { + api_key, + key1, + api_secret, + } => Self::SignatureKey { + api_key, + key1, + api_secret, + }, + api_models::admin::ConnectorAuthType::MultiAuthKey { + api_key, + key1, + api_secret, + key2, + } => Self::MultiAuthKey { + api_key, + key1, + api_secret, + key2, + }, + api_models::admin::ConnectorAuthType::CurrencyAuthKey { auth_key_map } => { + Self::CurrencyAuthKey { auth_key_map } + } + api_models::admin::ConnectorAuthType::NoKey => Self::NoKey, + } + } +} + +impl Into for ConnectorAuthType { + fn into(self) -> api_models::admin::ConnectorAuthType { + match self { + Self::TemporaryAuth => api_models::admin::ConnectorAuthType::TemporaryAuth, + Self::HeaderKey { api_key } => { + api_models::admin::ConnectorAuthType::HeaderKey { api_key } + } + Self::BodyKey { api_key, key1 } => { + api_models::admin::ConnectorAuthType::BodyKey { api_key, key1 } + } + Self::SignatureKey { + api_key, + key1, + api_secret, + } => api_models::admin::ConnectorAuthType::SignatureKey { + api_key, + key1, + api_secret, + }, + Self::MultiAuthKey { + api_key, + key1, + api_secret, + key2, + } => api_models::admin::ConnectorAuthType::MultiAuthKey { + api_key, + key1, + api_secret, + key2, + }, + Self::CurrencyAuthKey { auth_key_map } => { + api_models::admin::ConnectorAuthType::CurrencyAuthKey { auth_key_map } + } + Self::NoKey => api_models::admin::ConnectorAuthType::NoKey, + } + } +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectorsList { pub connectors: Vec, diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index 76a295c1db49..900b11711168 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -1,8 +1,6 @@ pub mod paypal; pub mod stripe; -use api_models::enums as api_enums; -use common_utils::events::{ApiEventMetric, ApiEventsType}; use error_stack::{IntoReport, ResultExt}; use router_env as env; @@ -15,14 +13,6 @@ use crate::{ AppState, }; -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] -pub struct VerifyConnectorRequest { - pub connector_name: api_enums::Connector, - pub connector_account_details: types::ConnectorAuthType, -} - -common_utils::impl_misc_api_event_type!(VerifyConnectorRequest); - #[derive(Clone, Debug)] pub struct VerifyConnectorData { pub connector: &'static (dyn types::api::Connector + Sync),