mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +08:00
feat(macro): add config validation macro for connectors (#1755)
This commit is contained in:
@ -423,7 +423,7 @@ pub struct SupportedConnectors {
|
||||
pub wallets: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
|
||||
#[serde(default)]
|
||||
pub struct Connectors {
|
||||
pub aci: ConnectorParams,
|
||||
@ -476,26 +476,23 @@ pub struct Connectors {
|
||||
pub worldline: ConnectorParams,
|
||||
pub worldpay: ConnectorParams,
|
||||
pub zen: ConnectorParams,
|
||||
|
||||
// Keep this field separate from the remaining fields
|
||||
pub supported: SupportedConnectors,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
|
||||
#[serde(default)]
|
||||
pub struct ConnectorParams {
|
||||
pub base_url: String,
|
||||
pub secondary_base_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
|
||||
#[serde(default)]
|
||||
pub struct ConnectorParamsWithMoreUrls {
|
||||
pub base_url: String,
|
||||
pub base_url_bank_redirects: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
|
||||
#[serde(default)]
|
||||
pub struct ConnectorParamsWithFileUploadUrl {
|
||||
pub base_url: String,
|
||||
@ -503,7 +500,7 @@ pub struct ConnectorParamsWithFileUploadUrl {
|
||||
}
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[derive(Debug, Deserialize, Clone, Default, router_derive::ConfigValidate)]
|
||||
#[serde(default)]
|
||||
pub struct ConnectorParamsWithSecondaryBaseUrl {
|
||||
pub base_url: String,
|
||||
@ -675,7 +672,7 @@ impl Settings {
|
||||
}
|
||||
self.secrets.validate()?;
|
||||
self.locker.validate()?;
|
||||
self.connectors.validate()?;
|
||||
self.connectors.validate("connectors")?;
|
||||
|
||||
self.scheduler
|
||||
.as_ref()
|
||||
|
||||
@ -129,68 +129,6 @@ impl super::settings::SupportedConnectors {
|
||||
}
|
||||
}
|
||||
|
||||
impl super::settings::Connectors {
|
||||
pub fn validate(&self) -> Result<(), ApplicationError> {
|
||||
self.aci.validate()?;
|
||||
self.adyen.validate()?;
|
||||
self.applepay.validate()?;
|
||||
self.authorizedotnet.validate()?;
|
||||
self.braintree.validate()?;
|
||||
self.checkout.validate()?;
|
||||
self.cybersource.validate()?;
|
||||
self.globalpay.validate()?;
|
||||
self.klarna.validate()?;
|
||||
self.shift4.validate()?;
|
||||
self.stripe.validate()?;
|
||||
self.worldpay.validate()?;
|
||||
|
||||
self.supported.validate()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl super::settings::ConnectorParams {
|
||||
pub fn validate(&self) -> Result<(), ApplicationError> {
|
||||
common_utils::fp_utils::when(self.base_url.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"connector base URL must not be empty".into(),
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl super::settings::ConnectorParamsWithFileUploadUrl {
|
||||
pub fn validate(&self) -> Result<(), ApplicationError> {
|
||||
common_utils::fp_utils::when(self.base_url.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"connector base URL must not be empty".into(),
|
||||
))
|
||||
})?;
|
||||
common_utils::fp_utils::when(self.base_url_file_upload.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"connector file upload base URL must not be empty".into(),
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
impl super::settings::ConnectorParamsWithSecondaryBaseUrl {
|
||||
pub fn validate(&self) -> Result<(), ApplicationError> {
|
||||
common_utils::fp_utils::when(self.base_url.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"connector base URL must not be empty".into(),
|
||||
))
|
||||
})?;
|
||||
common_utils::fp_utils::when(self.secondary_base_url.is_default_or_empty(), || {
|
||||
Err(ApplicationError::InvalidConfigurationValueError(
|
||||
"connector secondary base URL must not be empty".into(),
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl super::settings::SchedulerSettings {
|
||||
pub fn validate(&self) -> Result<(), ApplicationError> {
|
||||
use common_utils::fp_utils::when;
|
||||
|
||||
Reference in New Issue
Block a user