Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): added api for the deleting config key (#3554)
Tanbir Alibbb3d3d1e26f
diff --git a/crates/diesel_models/src/query/configs.rs b/crates/diesel_models/src/query/configs.rsindex 62ed60e3b0..306fb5e335 100644--- a/crates/diesel_models/src/query/configs.rs+++ b/crates/diesel_models/src/query/configs.rs@@ -50,8 +50,11 @@ impl Config {}#[instrument(skip(conn))]- pub async fn delete_by_key(conn: &PgPooledConn, key: &str) -> StorageResult<bool> {- generics::generic_delete::<<Self as HasTable>::Table, _>(conn, dsl::key.eq(key.to_owned()))- .await+ pub async fn delete_by_key(conn: &PgPooledConn, key: &str) -> StorageResult<Self> {+ generics::generic_delete_one_with_result::<<Self as HasTable>::Table, _, _>(+ conn,+ dsl::key.eq(key.to_owned()),+ )+ .await}}diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rsindex 8aa2310416..ba2303167d 100644--- a/crates/router/src/core/configs.rs+++ b/crates/router/src/core/configs.rs@@ -41,3 +41,12 @@ pub async fn update_config(.to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?;Ok(ApplicationResponse::Json(config.foreign_into()))}++pub async fn config_delete(state: AppState, key: String) -> RouterResponse<api::Config> {+ let store = state.store.as_ref();+ let config = store+ .delete_config_by_key(&key)+ .await+ .to_not_found_response(errors::ApiErrorResponse::ConfigNotFound)?;+ Ok(ApplicationResponse::Json(config.foreign_into()))+}diff --git a/crates/router/src/db/configs.rs b/crates/router/src/db/configs.rsindex f3e85ba5d2..1d472c1fb6 100644--- a/crates/router/src/db/configs.rs+++ b/crates/router/src/db/configs.rs@@ -51,7 +51,10 @@ pub trait ConfigInterface {config_update: storage::ConfigUpdate,) -> CustomResult<storage::Config, errors::StorageError>;- async fn delete_config_by_key(&self, key: &str) -> CustomResult<bool, errors::StorageError>;+ async fn delete_config_by_key(+ &self,+ key: &str,+ ) -> CustomResult<storage::Config, errors::StorageError>;}#[async_trait::async_trait]@@ -154,7 +157,10 @@ impl ConfigInterface for Store {cache::get_or_populate_in_memory(self, key, find_else_unwrap_or, &CONFIG_CACHE).await}- async fn delete_config_by_key(&self, key: &str) -> CustomResult<bool, errors::StorageError> {+ async fn delete_config_by_key(+ &self,+ key: &str,+ ) -> CustomResult<storage::Config, errors::StorageError> {let conn = connection::pg_connection_write(self).await?;let deleted = storage::Config::delete_by_key(&conn, key).await@@ -226,15 +232,15 @@ impl ConfigInterface for MockDb {result}- async fn delete_config_by_key(&self, key: &str) -> CustomResult<bool, errors::StorageError> {+ async fn delete_config_by_key(+ &self,+ key: &str,+ ) -> CustomResult<storage::Config, errors::StorageError> {let mut configs = self.configs.lock().await;let result = configs.iter().position(|c| c.key == key)- .map(|index| {- configs.remove(index);- true- })+ .map(|index| configs.remove(index)).ok_or_else(|| {errors::StorageError::ValueNotFound("cannot find config to delete".to_string()).into()diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex 78b95544ca..c90e561d88 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -284,7 +284,10 @@ impl ConfigInterface for KafkaStore {.await}- async fn delete_config_by_key(&self, key: &str) -> CustomResult<bool, errors::StorageError> {+ async fn delete_config_by_key(+ &self,+ key: &str,+ ) -> CustomResult<storage::Config, errors::StorageError> {self.diesel_store.delete_config_by_key(key).await}diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex e9e4b67c78..26f5b52807 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -813,7 +813,8 @@ impl Configs {.service(web::resource("/{key}").route(web::get().to(config_key_retrieve))- .route(web::post().to(config_key_update)),+ .route(web::post().to(config_key_update))+ .route(web::delete().to(config_key_delete)),)}}diff --git a/crates/router/src/routes/configs.rs b/crates/router/src/routes/configs.rsindex 45eb45a83b..d7e96f4023 100644--- a/crates/router/src/routes/configs.rs+++ b/crates/router/src/routes/configs.rs@@ -71,3 +71,24 @@ pub async fn config_key_update().await}++#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyDelete))]+pub async fn config_key_delete(+ state: web::Data<AppState>,+ req: HttpRequest,+ path: web::Path<String>,+) -> impl Responder {+ let flow = Flow::ConfigKeyDelete;+ let key = path.into_inner();++ api::server_wrap(+ flow,+ state,+ &req,+ key,+ |state, _, key| configs::config_delete(state, key),+ &auth::AdminApiAuth,+ api_locking::LockAction::NotApplicable,+ )+ .await+}diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex efdbb57b33..e3b04bd3f7 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -74,6 +74,7 @@ impl From<Flow> for ApiIdentifier {Flow::ConfigKeyCreate| Flow::ConfigKeyFetch| Flow::ConfigKeyUpdate+ | Flow::ConfigKeyDelete| Flow::CreateConfigKey => Self::Configs,Flow::CustomersCreatediff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex 994b134520..b2e665059e 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -82,6 +82,8 @@ pub enum Flow {ConfigKeyFetch,/// ConfigKey Update flow.ConfigKeyUpdate,+ /// ConfigKey Delete flow.+ ConfigKeyDelete,/// Customers create flow.CustomersCreate,/// Customers retrieve flow.