refactor: Added api-key auth for routing APIs (#8083)

Co-authored-by: Prajjwal kumar <write2prajjwal@gmail.com>
This commit is contained in:
Sarthak Soni
2025-05-21 19:48:13 +05:30
committed by GitHub
parent 1238ae77de
commit 278618cc1e
2 changed files with 17 additions and 59 deletions

View File

@ -1752,10 +1752,13 @@ where
let algo_type_enabled_features = algo_type.get_enabled_features(); let algo_type_enabled_features = algo_type.get_enabled_features();
if *algo_type_enabled_features == feature_to_enable { if *algo_type_enabled_features == feature_to_enable {
// algorithm already has the required feature // algorithm already has the required feature
return Err(errors::ApiErrorResponse::PreconditionFailed { let routing_algorithm = db
message: format!("{} is already enabled", dynamic_routing_type), .find_routing_algorithm_by_profile_id_algorithm_id(&profile_id, &algo_type_algorithm_id)
} .await
.into()); .to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;
let updated_routing_record = routing_algorithm.foreign_into();
return Ok(ApplicationResponse::Json(updated_routing_record));
}; };
*algo_type_enabled_features = feature_to_enable; *algo_type_enabled_features = feature_to_enable;
dynamic_routing_algo_ref.update_enabled_features(dynamic_routing_type, feature_to_enable); dynamic_routing_algo_ref.update_enabled_features(dynamic_routing_type, feature_to_enable);

View File

@ -42,7 +42,6 @@ pub async fn routing_create_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -53,10 +52,6 @@ pub async fn routing_create_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingWrite,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -134,7 +129,6 @@ pub async fn routing_link_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -145,10 +139,6 @@ pub async fn routing_link_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingWrite,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -233,7 +223,6 @@ pub async fn routing_retrieve_config(
algorithm_id, algorithm_id,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -244,10 +233,6 @@ pub async fn routing_retrieve_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingRead,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -324,7 +309,6 @@ pub async fn list_routing_configs(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -335,10 +319,6 @@ pub async fn list_routing_configs(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::MerchantRoutingRead,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -370,7 +350,6 @@ pub async fn list_routing_configs_for_profile(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -381,10 +360,6 @@ pub async fn list_routing_configs_for_profile(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingRead,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -464,7 +439,6 @@ pub async fn routing_unlink_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -475,10 +449,6 @@ pub async fn routing_unlink_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingWrite,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -556,7 +526,6 @@ pub async fn routing_update_default_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -567,10 +536,6 @@ pub async fn routing_update_default_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::MerchantRoutingWrite,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -644,9 +609,16 @@ pub async fn routing_retrieve_default_config(
transaction_type, transaction_type,
) )
}, },
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false,
is_platform_allowed: false,
}),
&auth::JWTAuth { &auth::JWTAuth {
permission: Permission::ProfileRoutingRead, permission: Permission::ProfileRoutingRead,
}, },
req.headers(),
),
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -992,7 +964,6 @@ pub async fn routing_retrieve_linked_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -1004,11 +975,6 @@ pub async fn routing_retrieve_linked_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuthProfileFromRoute {
profile_id,
required_permission: Permission::ProfileRoutingRead,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -1030,7 +996,6 @@ pub async fn routing_retrieve_linked_config(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -1041,10 +1006,6 @@ pub async fn routing_retrieve_linked_config(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuth {
permission: Permission::ProfileRoutingRead,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await
@ -1184,7 +1145,6 @@ pub async fn routing_update_default_config_for_profile(
transaction_type, transaction_type,
) )
}, },
#[cfg(not(feature = "release"))]
auth::auth_type( auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth { &auth::HeaderAuth(auth::ApiKeyAuth {
is_connected_allowed: false, is_connected_allowed: false,
@ -1196,11 +1156,6 @@ pub async fn routing_update_default_config_for_profile(
}, },
req.headers(), req.headers(),
), ),
#[cfg(feature = "release")]
&auth::JWTAuthProfileFromRoute {
profile_id: routing_payload_wrapper.profile_id,
required_permission: Permission::ProfileRoutingWrite,
},
api_locking::LockAction::NotApplicable, api_locking::LockAction::NotApplicable,
)) ))
.await .await