SirajRLX commited on
Commit
e80f97d
·
verified ·
1 Parent(s): de28b9b

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. diffs/pr_10025/1245d9a/diff.json +0 -0
  2. diffs/pr_10025/15190c5/diff.json +110 -0
  3. diffs/pr_10025/4d25fb5/diff.json +0 -0
  4. diffs/pr_10025/9bedc92/diff.json +54 -0
  5. diffs/pr_10025/ff44966/diff.json +0 -0
  6. diffs/pr_10071/17d77c7/diff.json +6 -0
  7. diffs/pr_10071/ba9963e/diff.json +6 -0
  8. diffs/pr_10080/0c197b6/diff.json +184 -0
  9. diffs/pr_10080/0cdddb5/diff.json +39 -0
  10. diffs/pr_10080/1e024a1/diff.json +192 -0
  11. diffs/pr_10080/28781e8/diff.json +235 -0
  12. diffs/pr_10080/2bfa3fc/diff.json +0 -0
  13. diffs/pr_10080/40ff6f2/diff.json +40 -0
  14. diffs/pr_10080/57fa606/diff.json +171 -0
  15. diffs/pr_10080/7959c36/diff.json +24 -0
  16. diffs/pr_10080/979147e/diff.json +6 -0
  17. diffs/pr_10080/9e04455/diff.json +56 -0
  18. diffs/pr_10080/aea832f/diff.json +24 -0
  19. diffs/pr_10080/b608274/diff.json +98 -0
  20. diffs/pr_10080/cb10d10/diff.json +44 -0
  21. diffs/pr_10080/d1cd4a3/diff.json +45 -0
  22. diffs/pr_10080/d93a078/diff.json +148 -0
  23. diffs/pr_10080/f238248/diff.json +0 -0
  24. diffs/pr_10080/f69bde8/diff.json +85 -0
  25. diffs/pr_10158/0227ec9/diff.json +161 -0
  26. diffs/pr_10158/0c2988e/diff.json +44 -0
  27. diffs/pr_10158/152e71c/diff.json +24 -0
  28. diffs/pr_10158/1aaa136/diff.json +165 -0
  29. diffs/pr_10158/1df534e/diff.json +24 -0
  30. diffs/pr_10158/1e044ba/diff.json +84 -0
  31. diffs/pr_10158/34cfedc/diff.json +39 -0
  32. diffs/pr_10158/381ff3b/diff.json +39 -0
  33. diffs/pr_10158/3ea3282/diff.json +39 -0
  34. diffs/pr_10158/4c4b7f4/diff.json +24 -0
  35. diffs/pr_10158/4f0c898/diff.json +33 -0
  36. diffs/pr_10158/575fed7/diff.json +64 -0
  37. diffs/pr_10158/5a7fbf3/diff.json +6 -0
  38. diffs/pr_10158/5e6a702/diff.json +54 -0
  39. diffs/pr_10158/6f74057/diff.json +34 -0
  40. diffs/pr_10158/784bb96/diff.json +54 -0
  41. diffs/pr_10158/78b293b/diff.json +24 -0
  42. diffs/pr_10158/7fa4343/diff.json +24 -0
  43. diffs/pr_10158/90673b5/diff.json +111 -0
  44. diffs/pr_10158/9b8080e/diff.json +69 -0
  45. diffs/pr_10158/a68697e/diff.json +62 -0
  46. diffs/pr_10158/acdb837/diff.json +90 -0
  47. diffs/pr_10158/af4489c/diff.json +74 -0
  48. diffs/pr_10158/c1d8ffc/diff.json +24 -0
  49. diffs/pr_10158/de60299/diff.json +120 -0
  50. diffs/pr_10158/e5a739c/diff.json +24 -0
diffs/pr_10025/1245d9a/diff.json ADDED
The diff for this file is too large to render. See raw diff
 
diffs/pr_10025/15190c5/diff.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3",
3
+ "pr_number": 10025,
4
+ "rust_files": [
5
+ "crates/hyperswitch_connectors/src/connectors/payjustnow.rs",
6
+ "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::impl::PayjustnowRefundRequest",
11
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
12
+ "kind": "impl_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": false,
16
+ "before_code": "impl<F> TryFrom<&RefundsRouterData<F>> for PayjustnowRefundRequest {\n type Error = error_stack::Report<errors::ConnectorError>;\n fn try_from(item: &RefundsRouterData<F>) -> Result<Self, Self::Error> {\n Ok(Self {\n request_id: Some(item.request.refund_id.clone()),\n checkout_token: item.request.connector_transaction_id.clone(),\n merchant_refund_reference: item.request.refund_id.clone(),\n refund_amount_cents: item.request.minor_refund_amount,\n refund_description: item\n .request\n .reason\n .clone()\n .unwrap_or(\"No reason provided\".to_string()),\n })\n }\n}",
17
+ "after_code": "impl<F> TryFrom<&RefundsRouterData<F>> for PayjustnowRefundRequest {\n type Error = error_stack::Report<errors::ConnectorError>;\n fn try_from(item: &RefundsRouterData<F>) -> Result<Self, Self::Error> {\n Ok(Self {\n request_id: Some(item.request.refund_id.clone()),\n checkout_token: item.request.connector_transaction_id.clone(),\n merchant_refund_reference: item.request.refund_id.clone(),\n refund_amount_cents: item.request.minor_refund_amount,\n refund_description: item\n .request\n .reason\n .clone()\n .unwrap_or(NO_REFUND_REASON.to_string()),\n })\n }\n}",
18
+ "diff_span": {
19
+ "before": " .reason\n .clone()\n .unwrap_or(\"No reason provided\".to_string()),\n })\n }",
20
+ "after": " .reason\n .clone()\n .unwrap_or(NO_REFUND_REASON.to_string()),\n })\n }"
21
+ },
22
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
23
+ },
24
+ {
25
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::PayjustnowRefundRequest::function::try_from",
26
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
27
+ "kind": "function_item",
28
+ "status": "modified",
29
+ "code_changed": true,
30
+ "imports_changed": false,
31
+ "before_code": "fn try_from(item: &RefundsRouterData<F>) -> Result<Self, Self::Error> {\n Ok(Self {\n request_id: Some(item.request.refund_id.clone()),\n checkout_token: item.request.connector_transaction_id.clone(),\n merchant_refund_reference: item.request.refund_id.clone(),\n refund_amount_cents: item.request.minor_refund_amount,\n refund_description: item\n .request\n .reason\n .clone()\n .unwrap_or(\"No reason provided\".to_string()),\n })\n }",
32
+ "after_code": "fn try_from(item: &RefundsRouterData<F>) -> Result<Self, Self::Error> {\n Ok(Self {\n request_id: Some(item.request.refund_id.clone()),\n checkout_token: item.request.connector_transaction_id.clone(),\n merchant_refund_reference: item.request.refund_id.clone(),\n refund_amount_cents: item.request.minor_refund_amount,\n refund_description: item\n .request\n .reason\n .clone()\n .unwrap_or(NO_REFUND_REASON.to_string()),\n })\n }",
33
+ "diff_span": {
34
+ "before": " .reason\n .clone()\n .unwrap_or(\"No reason provided\".to_string()),\n })\n }",
35
+ "after": " .reason\n .clone()\n .unwrap_or(NO_REFUND_REASON.to_string()),\n })\n }"
36
+ },
37
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
38
+ },
39
+ {
40
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs::Payjustnow::function::validate_psync_reference_id",
41
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs",
42
+ "kind": "function_item",
43
+ "status": "modified",
44
+ "code_changed": true,
45
+ "imports_changed": false,
46
+ "before_code": "fn validate_psync_reference_id(\n &self,\n _data: &PaymentsSyncData,\n _is_three_ds: bool,\n _status: enums::AttemptStatus,\n _connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<(), errors::ConnectorError> {\n Ok(())\n }",
47
+ "after_code": "fn validate_psync_reference_id(\n &self,\n data: &PaymentsSyncData,\n _is_three_ds: bool,\n _status: enums::AttemptStatus,\n _connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<(), errors::ConnectorError> {\n if data.encoded_data.is_some()\n || data\n .connector_transaction_id\n .get_connector_transaction_id()\n .is_ok()\n {\n return Ok(());\n }\n\n Err(errors::ConnectorError::MissingConnectorTransactionID.into())\n }",
48
+ "diff_span": {
49
+ "before": "fn validate_psync_reference_id(\n &self,\n _data: &PaymentsSyncData,\n _is_three_ds: bool,\n _status: enums::AttemptStatus,\n _connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<(), errors::ConnectorError> {\n Ok(())\n }",
50
+ "after": "fn validate_psync_reference_id(\n &self,\n data: &PaymentsSyncData,\n _is_three_ds: bool,\n _status: enums::AttemptStatus,\n _connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<(), errors::ConnectorError> {\n if data.encoded_data.is_some()\n || data\n .connector_transaction_id\n .get_connector_transaction_id()\n .is_ok()\n {\n return Ok(());\n }\n\n Err(errors::ConnectorError::MissingConnectorTransactionID.into())\n }"
51
+ },
52
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
53
+ },
54
+ {
55
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::impl::PayjustnowPaymentsRequest",
56
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
57
+ "kind": "impl_item",
58
+ "status": "modified",
59
+ "code_changed": true,
60
+ "imports_changed": false,
61
+ "before_code": "impl TryFrom<&PayjustnowRouterData<&PaymentsAuthorizeRouterData>> for PayjustnowPaymentsRequest {\n type Error = error_stack::Report<errors::ConnectorError>;\n fn try_from(\n item: &PayjustnowRouterData<&PaymentsAuthorizeRouterData>,\n ) -> Result<Self, Self::Error> {\n let router_data = item.router_data;\n let order_items = router_data\n .request\n .order_details\n .as_ref()\n .map(|order_details| {\n order_details\n .iter()\n .map(|order| {\n Ok(OrderItem {\n name: order.product_name.clone(),\n sku: order.product_id.clone().unwrap_or_default(),\n quantity: u32::from(order.quantity),\n price_cents: order.amount,\n // image_url: order.product_img_link.clone().unwrap_or_default(),\n // category: order.category.clone().unwrap_or_default(),\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let confirm_redirect_url = \"https://www.google.com/\".to_string();\n let cancel_redirect_url = \"https://www.google.com/\".to_string();\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url,\n cancel_redirect_url,\n };\n\n Ok(Self {\n payjustnow: payjustnow_request,\n checkout_total_cents: item.amount,\n })\n }\n}",
62
+ "after_code": "impl TryFrom<&PayjustnowRouterData<&PaymentsAuthorizeRouterData>> for PayjustnowPaymentsRequest {\n type Error = error_stack::Report<errors::ConnectorError>;\n fn try_from(\n item: &PayjustnowRouterData<&PaymentsAuthorizeRouterData>,\n ) -> Result<Self, Self::Error> {\n let router_data = item.router_data;\n let order_items = router_data\n .request\n .order_details\n .as_ref()\n .map(|order_details| {\n order_details\n .iter()\n .map(|order| {\n Ok(OrderItem {\n name: order.product_name.clone(),\n sku: order.product_id.clone().unwrap_or_default(),\n quantity: u32::from(order.quantity),\n price_cents: order.amount,\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let router_return_url = item.router_data.request.get_router_return_url()?;\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url: router_return_url.clone(),\n cancel_redirect_url: router_return_url,\n };\n\n Ok(Self {\n payjustnow: payjustnow_request,\n checkout_total_cents: item.amount,\n })\n }\n}",
63
+ "diff_span": {
64
+ "before": " quantity: u32::from(order.quantity),\n price_cents: order.amount,\n // image_url: order.product_img_link.clone().unwrap_or_default(),\n // category: order.category.clone().unwrap_or_default(),\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let confirm_redirect_url = \"https://www.google.com/\".to_string();\n let cancel_redirect_url = \"https://www.google.com/\".to_string();\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url,\n cancel_redirect_url,\n };\n",
65
+ "after": " });\n\n let router_return_url = item.router_data.request.get_router_return_url()?;\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url: router_return_url.clone(),\n cancel_redirect_url: router_return_url,\n };\n"
66
+ },
67
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
68
+ },
69
+ {
70
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::PayjustnowPaymentsRequest::function::try_from",
71
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
72
+ "kind": "function_item",
73
+ "status": "modified",
74
+ "code_changed": true,
75
+ "imports_changed": false,
76
+ "before_code": "fn try_from(\n item: &PayjustnowRouterData<&PaymentsAuthorizeRouterData>,\n ) -> Result<Self, Self::Error> {\n let router_data = item.router_data;\n let order_items = router_data\n .request\n .order_details\n .as_ref()\n .map(|order_details| {\n order_details\n .iter()\n .map(|order| {\n Ok(OrderItem {\n name: order.product_name.clone(),\n sku: order.product_id.clone().unwrap_or_default(),\n quantity: u32::from(order.quantity),\n price_cents: order.amount,\n // image_url: order.product_img_link.clone().unwrap_or_default(),\n // category: order.category.clone().unwrap_or_default(),\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let confirm_redirect_url = \"https://www.google.com/\".to_string();\n let cancel_redirect_url = \"https://www.google.com/\".to_string();\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url,\n cancel_redirect_url,\n };\n\n Ok(Self {\n payjustnow: payjustnow_request,\n checkout_total_cents: item.amount,\n })\n }",
77
+ "after_code": "fn try_from(\n item: &PayjustnowRouterData<&PaymentsAuthorizeRouterData>,\n ) -> Result<Self, Self::Error> {\n let router_data = item.router_data;\n let order_items = router_data\n .request\n .order_details\n .as_ref()\n .map(|order_details| {\n order_details\n .iter()\n .map(|order| {\n Ok(OrderItem {\n name: order.product_name.clone(),\n sku: order.product_id.clone().unwrap_or_default(),\n quantity: u32::from(order.quantity),\n price_cents: order.amount,\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let router_return_url = item.router_data.request.get_router_return_url()?;\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url: router_return_url.clone(),\n cancel_redirect_url: router_return_url,\n };\n\n Ok(Self {\n payjustnow: payjustnow_request,\n checkout_total_cents: item.amount,\n })\n }",
78
+ "diff_span": {
79
+ "before": " quantity: u32::from(order.quantity),\n price_cents: order.amount,\n // image_url: order.product_img_link.clone().unwrap_or_default(),\n // category: order.category.clone().unwrap_or_default(),\n })\n })\n .collect::<Result<Vec<OrderItem>, errors::ConnectorError>>()\n })\n .transpose()?;\n\n let customer = router_data\n .get_optional_billing_email()\n .or_else(|| item.router_data.request.email.clone())\n .map(|email| Customer {\n first_name: router_data.get_optional_billing_first_name(),\n last_name: router_data.get_optional_billing_last_name(),\n email,\n phone_number: router_data.get_optional_billing_phone_number(),\n });\n\n let billing_address = Some(Address {\n address_line1: router_data.get_optional_billing_line1(),\n address_line2: router_data.get_optional_billing_line2(),\n city: router_data.get_optional_billing_city(),\n province: router_data.get_optional_billing_state(),\n postal_code: item.router_data.get_optional_billing_zip(),\n });\n\n let shipping_address = Some(Address {\n address_line1: item.router_data.get_optional_shipping_line1(),\n address_line2: item.router_data.get_optional_shipping_line2(),\n city: item.router_data.get_optional_shipping_city(),\n province: item.router_data.get_optional_shipping_state(),\n postal_code: item.router_data.get_optional_shipping_zip(),\n });\n\n let confirm_redirect_url = \"https://www.google.com/\".to_string();\n let cancel_redirect_url = \"https://www.google.com/\".to_string();\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url,\n cancel_redirect_url,\n };\n",
80
+ "after": " });\n\n let router_return_url = item.router_data.request.get_router_return_url()?;\n\n let payjustnow_request = PayjustnowRequest {\n request_id: Some(item.router_data.payment_id.clone()),\n merchant_order_reference: router_data.connector_request_reference_id.clone(),\n order_amount_cents: item.amount,\n order_items,\n customer,\n billing_address,\n shipping_address,\n confirm_redirect_url: router_return_url.clone(),\n cancel_redirect_url: router_return_url,\n };\n"
81
+ },
82
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
83
+ },
84
+ {
85
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::struct::OrderItem",
86
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
87
+ "kind": "struct_item",
88
+ "status": "modified",
89
+ "code_changed": true,
90
+ "imports_changed": false,
91
+ "before_code": "pub struct OrderItem {\n name: String,\n sku: String,\n quantity: u32,\n price_cents: MinorUnit,\n // image_url: String,\n // category: String,\n}",
92
+ "after_code": "pub struct OrderItem {\n name: String,\n sku: String,\n quantity: u32,\n price_cents: MinorUnit,\n}",
93
+ "diff_span": {
94
+ "before": " quantity: u32,\n price_cents: MinorUnit,\n // image_url: String,\n // category: String,\n}",
95
+ "after": ""
96
+ },
97
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
98
+ },
99
+ {
100
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs::const::NO_REFUND_REASON",
101
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow/transformers.rs",
102
+ "kind": "const_item",
103
+ "status": "added",
104
+ "before_code": null,
105
+ "after_code": "const NO_REFUND_REASON: &str = \"No reason provided\";",
106
+ "diff_span": null,
107
+ "commit_sha": "15190c59749a33d2aca29849e348a50fccd7b8c3"
108
+ }
109
+ ]
110
+ }
diffs/pr_10025/4d25fb5/diff.json ADDED
The diff for this file is too large to render. See raw diff
 
diffs/pr_10025/9bedc92/diff.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "9bedc92c4f353b2b7d2707930e3b369b09cd496b",
3
+ "pr_number": 10025,
4
+ "rust_files": [
5
+ "crates/hyperswitch_connectors/src/connectors/payjustnow.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs::Payjustnow::function::get_webhook_source_verification_message",
10
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_webhook_source_verification_message(\n &self,\n request: &webhooks::IncomingWebhookRequestDetails<'_>,\n _merchant_id: &common_utils::id_type::MerchantId,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let body_with_no_whitespace = request\n .body\n .iter()\n .filter(|&b| !b.is_ascii_whitespace())\n .copied()\n .collect::<Vec<u8>>();\n\n Ok(body_with_no_whitespace)\n }",
16
+ "after_code": "fn get_webhook_source_verification_message(\n &self,\n request: &webhooks::IncomingWebhookRequestDetails<'_>,\n _merchant_id: &common_utils::id_type::MerchantId,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let message = request\n .body\n .iter()\n .filter(|&b| !b.is_ascii_whitespace())\n .copied()\n .collect::<Vec<u8>>();\n\n Ok(message)\n }",
17
+ "diff_span": {
18
+ "before": " _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let body_with_no_whitespace = request\n .body\n .iter()\n .filter(|&b| !b.is_ascii_whitespace())\n .copied()\n .collect::<Vec<u8>>();\n\n Ok(body_with_no_whitespace)\n }",
19
+ "after": " _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let message = request\n .body\n .iter()\n .filter(|&b| !b.is_ascii_whitespace())\n .copied()\n .collect::<Vec<u8>>();\n\n Ok(message)\n }"
20
+ },
21
+ "commit_sha": "9bedc92c4f353b2b7d2707930e3b369b09cd496b"
22
+ },
23
+ {
24
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs::Payjustnow::function::build_headers",
25
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "fn build_headers(\n &self,\n req: &RouterData<Flow, Request, Response>,\n _connectors: &Connectors,\n ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {\n let mut header = vec![\n (\n headers::CONTENT_TYPE.to_string(),\n self.get_content_type().to_string().into(),\n ),\n (\n headers::USER_AGENT.to_string(),\n hyperswitch_interfaces::consts::USER_AGENT\n .to_string()\n .into(),\n ),\n ];\n let mut api_key = self.get_auth_header(&req.connector_auth_type)?;\n header.append(&mut api_key);\n Ok(header)\n }",
31
+ "after_code": "fn build_headers(\n &self,\n req: &RouterData<Flow, Request, Response>,\n connectors: &Connectors,\n ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {\n let request_body = Self::get_request_body(self, req, connectors)?;\n\n let request_body_string =\n String::from_utf8(request_body.get_inner_value().peek().as_bytes().to_vec())\n .map_err(|_| errors::ConnectorError::RequestEncodingFailed)?;\n let request_body_string_without_whitespace =\n request_body_string.replace(char::is_whitespace, \"\");\n\n let auth = payjustnow::PayjustnowAuthType::try_from(&req.connector_auth_type)\n .change_context(errors::ConnectorError::FailedToObtainAuthType)?;\n\n let signature = crypto::HmacSha256::sign_message(\n &crypto::HmacSha256,\n auth.signing_key.expose().as_bytes(),\n request_body_string_without_whitespace.as_bytes(),\n )\n .change_context(errors::ConnectorError::RequestEncodingFailed)?;\n\n let signature_base64 = base64::engine::general_purpose::STANDARD.encode(signature);\n\n let mut headers = vec![\n (\n headers::CONTENT_TYPE.to_string(),\n self.get_content_type().to_string().into(),\n ),\n (\n headers::USER_AGENT.to_string(),\n hyperswitch_interfaces::consts::USER_AGENT\n .to_string()\n .into(),\n ),\n ];\n let mut api_key = self.get_auth_header(&req.connector_auth_type)?;\n headers.append(&mut api_key);\n headers.push((\"X-Signature\".to_string(), signature_base64.into_masked()));\n\n Ok(headers)\n }",
32
+ "diff_span": {
33
+ "before": " &self,\n req: &RouterData<Flow, Request, Response>,\n _connectors: &Connectors,\n ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {\n let mut header = vec![\n (\n headers::CONTENT_TYPE.to_string(),\n self.get_content_type().to_string().into(),\n ),\n (\n headers::USER_AGENT.to_string(),\n hyperswitch_interfaces::consts::USER_AGENT\n .to_string()\n .into(),\n ),\n ];\n let mut api_key = self.get_auth_header(&req.connector_auth_type)?;\n header.append(&mut api_key);\n Ok(header)\n }",
34
+ "after": " &self,\n req: &RouterData<Flow, Request, Response>,\n connectors: &Connectors,\n ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {\n let request_body = Self::get_request_body(self, req, connectors)?;\n\n let request_body_string =\n String::from_utf8(request_body.get_inner_value().peek().as_bytes().to_vec())\n .map_err(|_| errors::ConnectorError::RequestEncodingFailed)?;\n let request_body_string_without_whitespace =\n request_body_string.replace(char::is_whitespace, \"\");\n\n let auth = payjustnow::PayjustnowAuthType::try_from(&req.connector_auth_type)\n .change_context(errors::ConnectorError::FailedToObtainAuthType)?;\n\n let signature = crypto::HmacSha256::sign_message(\n &crypto::HmacSha256,\n auth.signing_key.expose().as_bytes(),\n request_body_string_without_whitespace.as_bytes(),\n )\n .change_context(errors::ConnectorError::RequestEncodingFailed)?;\n\n let signature_base64 = base64::engine::general_purpose::STANDARD.encode(signature);\n\n let mut headers = vec![\n (\n headers::CONTENT_TYPE.to_string(),\n self.get_content_type().to_string().into(),\n ),\n (\n headers::USER_AGENT.to_string(),\n hyperswitch_interfaces::consts::USER_AGENT\n .to_string()\n .into(),\n ),\n ];\n let mut api_key = self.get_auth_header(&req.connector_auth_type)?;\n headers.append(&mut api_key);\n headers.push((\"X-Signature\".to_string(), signature_base64.into_masked()));\n\n Ok(headers)\n }"
35
+ },
36
+ "commit_sha": "9bedc92c4f353b2b7d2707930e3b369b09cd496b"
37
+ },
38
+ {
39
+ "id": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs::Payjustnow::function::build_request",
40
+ "file": "crates/hyperswitch_connectors/src/connectors/payjustnow.rs",
41
+ "kind": "function_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "fn build_request(\n &self,\n req: &RefundSyncRouterData,\n connectors: &Connectors,\n ) -> CustomResult<Option<Request>, errors::ConnectorError> {\n let request_body = types::RefundSyncType::get_request_body(self, req, connectors)?;\n let request_body_string =\n String::from_utf8(request_body.get_inner_value().peek().as_bytes().to_vec())\n .map_err(|_| errors::ConnectorError::RequestEncodingFailed)?;\n let request_body_string_without_whitespace =\n request_body_string.replace(char::is_whitespace, \"\");\n\n let auth = payjustnow::PayjustnowAuthType::try_from(&req.connector_auth_type)\n .change_context(errors::ConnectorError::FailedToObtainAuthType)?;\n\n let signature = crypto::HmacSha256::sign_message(\n &crypto::HmacSha256,\n auth.signing_key.expose().as_bytes(),\n request_body_string_without_whitespace.as_bytes(),\n )\n .change_context(errors::ConnectorError::RequestEncodingFailed)?;\n\n let signature_base64 = base64::engine::general_purpose::STANDARD.encode(signature);\n\n let mut headers = self.get_headers(req, connectors)?;\n headers.push((\"X-Signature\".to_string(), signature_base64.into_masked()));\n\n Ok(Some(\n RequestBuilder::new()\n .method(Method::Post)\n .url(&types::RefundSyncType::get_url(self, req, connectors)?)\n .attach_default_headers()\n .headers(headers)\n .set_body(request_body)\n .build(),\n ))\n }",
46
+ "after_code": "fn build_request(\n &self,\n req: &RefundSyncRouterData,\n connectors: &Connectors,\n ) -> CustomResult<Option<Request>, errors::ConnectorError> {\n Ok(Some(\n RequestBuilder::new()\n .method(Method::Post)\n .url(&types::RefundSyncType::get_url(self, req, connectors)?)\n .attach_default_headers()\n .headers(self.get_headers(req, connectors)?)\n .set_body(self.get_request_body(req, connectors)?)\n .build(),\n ))\n }",
47
+ "diff_span": {
48
+ "before": " connectors: &Connectors,\n ) -> CustomResult<Option<Request>, errors::ConnectorError> {\n let request_body = types::RefundSyncType::get_request_body(self, req, connectors)?;\n let request_body_string =\n String::from_utf8(request_body.get_inner_value().peek().as_bytes().to_vec())\n .map_err(|_| errors::ConnectorError::RequestEncodingFailed)?;\n let request_body_string_without_whitespace =\n request_body_string.replace(char::is_whitespace, \"\");\n\n let auth = payjustnow::PayjustnowAuthType::try_from(&req.connector_auth_type)\n .change_context(errors::ConnectorError::FailedToObtainAuthType)?;\n\n let signature = crypto::HmacSha256::sign_message(\n &crypto::HmacSha256,\n auth.signing_key.expose().as_bytes(),\n request_body_string_without_whitespace.as_bytes(),\n )\n .change_context(errors::ConnectorError::RequestEncodingFailed)?;\n\n let signature_base64 = base64::engine::general_purpose::STANDARD.encode(signature);\n\n let mut headers = self.get_headers(req, connectors)?;\n headers.push((\"X-Signature\".to_string(), signature_base64.into_masked()));\n\n Ok(Some(\n RequestBuilder::new()\n .method(Method::Post)\n .url(&types::RefundSyncType::get_url(self, req, connectors)?)\n .attach_default_headers()\n .headers(headers)\n .set_body(request_body)\n .build(),\n ))",
49
+ "after": " .url(&types::RefundSyncType::get_url(self, req, connectors)?)\n .attach_default_headers()\n .headers(self.get_headers(req, connectors)?)\n .set_body(self.get_request_body(req, connectors)?)\n .build(),\n ))"
50
+ },
51
+ "commit_sha": "9bedc92c4f353b2b7d2707930e3b369b09cd496b"
52
+ }
53
+ ]
54
+ }
diffs/pr_10025/ff44966/diff.json ADDED
The diff for this file is too large to render. See raw diff
 
diffs/pr_10071/17d77c7/diff.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "17d77c78962cb525ee92c036278177c32ceadff1",
3
+ "pr_number": 10071,
4
+ "rust_files": [],
5
+ "diffs": []
6
+ }
diffs/pr_10071/ba9963e/diff.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "ba9963e844d239b1d02f949bdba346606f03852d",
3
+ "pr_number": 10071,
4
+ "rust_files": [],
5
+ "diffs": []
6
+ }
diffs/pr_10080/0c197b6/diff.json ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_connectors/src/connectors/santander.rs",
6
+ "crates/hyperswitch_interfaces/src/api.rs",
7
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
8
+ "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
9
+ "crates/router/src/core/payments/access_token.rs",
10
+ "crates/router/src/core/payouts/access_token.rs"
11
+ ],
12
+ "diffs": [
13
+ {
14
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorAccessTokenSuffix",
15
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
16
+ "kind": "trait_item",
17
+ "status": "modified",
18
+ "code_changed": true,
19
+ "imports_changed": false,
20
+ "before_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
21
+ "after_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
22
+ "diff_span": {
23
+ "before": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
24
+ "after": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
25
+ },
26
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
27
+ },
28
+ {
29
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::impl::BoxedConnectorV2",
30
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
31
+ "kind": "impl_item",
32
+ "status": "modified",
33
+ "code_changed": true,
34
+ "imports_changed": false,
35
+ "before_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
36
+ "after_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
37
+ "diff_span": {
38
+ "before": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,",
39
+ "after": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,"
40
+ },
41
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
42
+ },
43
+ {
44
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::impl::Santander",
45
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
46
+ "kind": "impl_item",
47
+ "status": "modified",
48
+ "code_changed": true,
49
+ "imports_changed": false,
50
+ "before_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }\n}",
51
+ "after_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }\n}",
52
+ "diff_span": {
53
+ "before": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
54
+ "after": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
55
+ },
56
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
57
+ },
58
+ {
59
+ "id": "crates/router/src/core/payments/access_token.rs::function::add_access_token",
60
+ "file": "crates/router/src/core/payments/access_token.rs",
61
+ "kind": "function_item",
62
+ "status": "modified",
63
+ "code_changed": true,
64
+ "imports_changed": false,
65
+ "before_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
66
+ "after_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name.clone(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!(\n \"Failed to get access token key for connector: {:?}\",\n connector.connector_name\n ))?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
67
+ "diff_span": {
68
+ "before": " .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store",
69
+ "after": " .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name.clone(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!(\n \"Failed to get access token key for connector: {:?}\",\n connector.connector_name\n ))?;\n\n let old_access_token = store"
70
+ },
71
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
72
+ },
73
+ {
74
+ "id": "crates/router/src/core/payouts/access_token.rs::function::add_access_token_for_payout",
75
+ "file": "crates/router/src/core/payouts/access_token.rs",
76
+ "kind": "function_item",
77
+ "status": "modified",
78
+ "code_changed": true,
79
+ "imports_changed": false,
80
+ "before_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
81
+ "after_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
82
+ "diff_span": {
83
+ "before": " let key = connector\n .connector\n .get_access_token_key_from_connector(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n",
84
+ "after": " let key = connector\n .connector\n .get_access_token_key(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n"
85
+ },
86
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
87
+ },
88
+ {
89
+ "id": "crates/hyperswitch_interfaces/src/api.rs::impl::BoxedConnector",
90
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
91
+ "kind": "impl_item",
92
+ "status": "modified",
93
+ "code_changed": true,
94
+ "imports_changed": false,
95
+ "before_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
96
+ "after_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
97
+ "diff_span": {
98
+ "before": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
99
+ "after": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
100
+ },
101
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
102
+ },
103
+ {
104
+ "id": "crates/hyperswitch_interfaces/src/api.rs::BoxedConnector::function::get_access_token_key",
105
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
106
+ "kind": "function_item",
107
+ "status": "added",
108
+ "before_code": null,
109
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
110
+ "diff_span": null,
111
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
112
+ },
113
+ {
114
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_key",
115
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
116
+ "kind": "function_item",
117
+ "status": "added",
118
+ "before_code": null,
119
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
120
+ "diff_span": null,
121
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
122
+ },
123
+ {
124
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::get_access_token_key",
125
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
126
+ "kind": "function_item",
127
+ "status": "added",
128
+ "before_code": null,
129
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }",
130
+ "diff_span": null,
131
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
132
+ },
133
+ {
134
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_key",
135
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
136
+ "kind": "function_item",
137
+ "status": "added",
138
+ "before_code": null,
139
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
140
+ "diff_span": null,
141
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
142
+ },
143
+ {
144
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_key_from_connector",
145
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
146
+ "kind": "function_item",
147
+ "status": "removed",
148
+ "before_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
149
+ "after_code": null,
150
+ "diff_span": null,
151
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
152
+ },
153
+ {
154
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::get_access_token_key_from_connector",
155
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
156
+ "kind": "function_item",
157
+ "status": "removed",
158
+ "before_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }",
159
+ "after_code": null,
160
+ "diff_span": null,
161
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
162
+ },
163
+ {
164
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_key_from_connector",
165
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
166
+ "kind": "function_item",
167
+ "status": "removed",
168
+ "before_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
169
+ "after_code": null,
170
+ "diff_span": null,
171
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
172
+ },
173
+ {
174
+ "id": "crates/hyperswitch_interfaces/src/api.rs::BoxedConnector::function::get_access_token_key_from_connector",
175
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
176
+ "kind": "function_item",
177
+ "status": "removed",
178
+ "before_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
179
+ "after_code": null,
180
+ "diff_span": null,
181
+ "commit_sha": "0c197b601ad247baa07f06c9dda55b4690e2a072"
182
+ }
183
+ ]
184
+ }
diffs/pr_10080/0cdddb5/diff.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "0cdddb59f13bf54ae63b89dc6b869881380c95d2",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/common_utils/src/id_type/merchant.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/common_utils/src/id_type/merchant.rs::impl::MerchantId",
10
+ "file": "crates/common_utils/src/id_type/merchant.rs",
11
+ "kind": "impl_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
16
+ "after_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
17
+ "diff_span": {
18
+ "before": " payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }\n",
19
+ "after": " payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }\n"
20
+ },
21
+ "commit_sha": "0cdddb59f13bf54ae63b89dc6b869881380c95d2"
22
+ },
23
+ {
24
+ "id": "crates/common_utils/src/id_type/merchant.rs::MerchantId::function::get_access_token_key",
25
+ "file": "crates/common_utils/src/id_type/merchant.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }",
31
+ "after_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }",
32
+ "diff_span": {
33
+ "before": " payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }",
34
+ "after": " payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }"
35
+ },
36
+ "commit_sha": "0cdddb59f13bf54ae63b89dc6b869881380c95d2"
37
+ }
38
+ ]
39
+ }
diffs/pr_10080/1e024a1/diff.json ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/common_utils/src/access_token.rs",
6
+ "crates/common_utils/src/id_type/merchant.rs",
7
+ "crates/router/src/db/kafka_store.rs",
8
+ "crates/router/src/db/merchant_connector_account.rs"
9
+ ],
10
+ "diffs": [
11
+ {
12
+ "id": "crates/router/src/db/merchant_connector_account.rs::Store::function::get_access_token",
13
+ "file": "crates/router/src/db/merchant_connector_account.rs",
14
+ "kind": "function_item",
15
+ "status": "modified",
16
+ "code_changed": true,
17
+ "imports_changed": false,
18
+ "before_code": "async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }",
19
+ "after_code": "async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }",
20
+ "diff_span": {
21
+ "before": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n",
22
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n"
23
+ },
24
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
25
+ },
26
+ {
27
+ "id": "crates/common_utils/src/id_type/merchant.rs::MerchantId::function::get_access_token_key",
28
+ "file": "crates/common_utils/src/id_type/merchant.rs",
29
+ "kind": "function_item",
30
+ "status": "modified",
31
+ "code_changed": true,
32
+ "imports_changed": false,
33
+ "before_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }",
34
+ "after_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> String {\n match access_token_key_suffix_from_connector {\n Some(key_suffix) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key_suffix\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }",
35
+ "diff_span": {
36
+ "before": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }",
37
+ "after": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> String {\n match access_token_key_suffix_from_connector {\n Some(key_suffix) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key_suffix\n )\n }"
38
+ },
39
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
40
+ },
41
+ {
42
+ "id": "crates/router/src/db/merchant_connector_account.rs::trait::ConnectorAccessToken",
43
+ "file": "crates/router/src/db/merchant_connector_account.rs",
44
+ "kind": "trait_item",
45
+ "status": "modified",
46
+ "code_changed": true,
47
+ "imports_changed": false,
48
+ "before_code": "pub trait ConnectorAccessToken {\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}",
49
+ "after_code": "pub trait ConnectorAccessToken {\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}",
50
+ "diff_span": {
51
+ "before": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}",
52
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}"
53
+ },
54
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
55
+ },
56
+ {
57
+ "id": "crates/router/src/db/merchant_connector_account.rs::impl::Store",
58
+ "file": "crates/router/src/db/merchant_connector_account.rs",
59
+ "kind": "impl_item",
60
+ "status": "modified",
61
+ "code_changed": true,
62
+ "imports_changed": false,
63
+ "before_code": "impl ConnectorAccessToken for Store {\n #[instrument(skip_all)]\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }\n}",
64
+ "after_code": "impl ConnectorAccessToken for Store {\n #[instrument(skip_all)]\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }\n}",
65
+ "diff_span": {
66
+ "before": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token",
67
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n let serialized_access_token = access_token"
68
+ },
69
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
70
+ },
71
+ {
72
+ "id": "crates/router/src/db/merchant_connector_account.rs::impl::MockDb",
73
+ "file": "crates/router/src/db/merchant_connector_account.rs",
74
+ "kind": "impl_item",
75
+ "status": "modified",
76
+ "code_changed": true,
77
+ "imports_changed": false,
78
+ "before_code": "impl ConnectorAccessToken for MockDb {\n async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }\n}",
79
+ "after_code": "impl ConnectorAccessToken for MockDb {\n async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }\n}",
80
+ "diff_span": {
81
+ "before": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())",
82
+ "after": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())"
83
+ },
84
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
85
+ },
86
+ {
87
+ "id": "crates/router/src/db/merchant_connector_account.rs::MockDb::function::get_access_token",
88
+ "file": "crates/router/src/db/merchant_connector_account.rs",
89
+ "kind": "function_item",
90
+ "status": "modified",
91
+ "code_changed": true,
92
+ "imports_changed": false,
93
+ "before_code": "async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }",
94
+ "after_code": "async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }",
95
+ "diff_span": {
96
+ "before": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)",
97
+ "after": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)"
98
+ },
99
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
100
+ },
101
+ {
102
+ "id": "crates/common_utils/src/access_token.rs::function::create_access_token_key",
103
+ "file": "crates/common_utils/src/access_token.rs",
104
+ "kind": "function_item",
105
+ "status": "modified",
106
+ "code_changed": true,
107
+ "imports_changed": false,
108
+ "before_code": "pub fn create_access_token_key(\n merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name, payment_method_type)\n}",
109
+ "after_code": "pub fn create_access_token_key(\n merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n )\n}",
110
+ "diff_span": {
111
+ "before": " merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name, payment_method_type)\n}",
112
+ "after": " merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n )\n}"
113
+ },
114
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
115
+ },
116
+ {
117
+ "id": "crates/router/src/db/kafka_store.rs::KafkaStore::function::get_access_token",
118
+ "file": "crates/router/src/db/kafka_store.rs",
119
+ "kind": "function_item",
120
+ "status": "modified",
121
+ "code_changed": true,
122
+ "imports_changed": false,
123
+ "before_code": "async fn get_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id, payment_method_type)\n .await\n }",
124
+ "after_code": "async fn get_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(\n merchant_id,\n merchant_connector_id,\n access_token_key_suffix_from_connector,\n )\n .await\n }",
125
+ "diff_span": {
126
+ "before": " merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id, payment_method_type)\n .await\n }",
127
+ "after": " merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(\n merchant_id,\n merchant_connector_id,\n access_token_key_suffix_from_connector,\n )\n .await\n }"
128
+ },
129
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
130
+ },
131
+ {
132
+ "id": "crates/common_utils/src/id_type/merchant.rs::impl::MerchantId",
133
+ "file": "crates/common_utils/src/id_type/merchant.rs",
134
+ "kind": "impl_item",
135
+ "status": "modified",
136
+ "code_changed": true,
137
+ "imports_changed": false,
138
+ "before_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
139
+ "after_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> String {\n match access_token_key_suffix_from_connector {\n Some(key_suffix) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key_suffix\n )\n }\n None => {\n format!(\n \"access_token_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n }\n }\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
140
+ "diff_span": {
141
+ "before": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n match payment_method_type {\n Some(pmt) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n pmt\n )\n }",
142
+ "after": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> String {\n match access_token_key_suffix_from_connector {\n Some(key_suffix) => {\n format!(\n \"access_token_{}_{}_{}\",\n self.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key_suffix\n )\n }"
143
+ },
144
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
145
+ },
146
+ {
147
+ "id": "crates/router/src/db/kafka_store.rs::KafkaStore::function::set_access_token",
148
+ "file": "crates/router/src/db/kafka_store.rs",
149
+ "kind": "function_item",
150
+ "status": "modified",
151
+ "code_changed": true,
152
+ "imports_changed": false,
153
+ "before_code": "async fn set_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token: AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n payment_method_type,\n )\n .await\n }",
154
+ "after_code": "async fn set_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token: AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n access_token_key_suffix_from_connector,\n )\n .await\n }",
155
+ "diff_span": {
156
+ "before": " merchant_connector_id: &str,\n access_token: AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n payment_method_type,\n )\n .await",
157
+ "after": " merchant_connector_id: &str,\n access_token: AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n access_token_key_suffix_from_connector,\n )\n .await"
158
+ },
159
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
160
+ },
161
+ {
162
+ "id": "crates/router/src/db/merchant_connector_account.rs::MockDb::function::set_access_token",
163
+ "file": "crates/router/src/db/merchant_connector_account.rs",
164
+ "kind": "function_item",
165
+ "status": "modified",
166
+ "code_changed": true,
167
+ "imports_changed": false,
168
+ "before_code": "async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }",
169
+ "after_code": "async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }",
170
+ "diff_span": {
171
+ "before": " _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())",
172
+ "after": " _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())"
173
+ },
174
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
175
+ },
176
+ {
177
+ "id": "crates/router/src/db/merchant_connector_account.rs::Store::function::set_access_token",
178
+ "file": "crates/router/src/db/merchant_connector_account.rs",
179
+ "kind": "function_item",
180
+ "status": "modified",
181
+ "code_changed": true,
182
+ "imports_changed": false,
183
+ "before_code": "async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }",
184
+ "after_code": "async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }",
185
+ "diff_span": {
186
+ "before": " merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token",
187
+ "after": " merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n access_token_key_suffix_from_connector: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n access_token_key_suffix_from_connector,\n );\n let serialized_access_token = access_token"
188
+ },
189
+ "commit_sha": "1e024a149d15b5a6bb69758e41cf0d3703fe8e69"
190
+ }
191
+ ]
192
+ }
diffs/pr_10080/28781e8/diff.json ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/common_enums/src/connector_enums.rs",
6
+ "crates/common_utils/src/access_token.rs",
7
+ "crates/common_utils/src/id_type/merchant.rs",
8
+ "crates/router/src/core/payments/access_token.rs",
9
+ "crates/router/src/core/payouts/access_token.rs",
10
+ "crates/router/src/db/kafka_store.rs",
11
+ "crates/router/src/db/merchant_connector_account.rs"
12
+ ],
13
+ "diffs": [
14
+ {
15
+ "id": "crates/router/src/db/merchant_connector_account.rs::Store::function::get_access_token",
16
+ "file": "crates/router/src/db/merchant_connector_account.rs",
17
+ "kind": "function_item",
18
+ "status": "modified",
19
+ "code_changed": true,
20
+ "imports_changed": false,
21
+ "before_code": "async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }",
22
+ "after_code": "async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }",
23
+ "diff_span": {
24
+ "before": "",
25
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n"
26
+ },
27
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
28
+ },
29
+ {
30
+ "id": "crates/common_utils/src/id_type/merchant.rs::MerchantId::function::get_access_token_key",
31
+ "file": "crates/common_utils/src/id_type/merchant.rs",
32
+ "kind": "function_item",
33
+ "status": "modified",
34
+ "code_changed": true,
35
+ "imports_changed": false,
36
+ "before_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}\",\n self.get_string_repr()\n )\n }",
37
+ "after_code": "pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }",
38
+ "diff_span": {
39
+ "before": " ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}\",\n self.get_string_repr()\n )\n }",
40
+ "after": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }"
41
+ },
42
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
43
+ },
44
+ {
45
+ "id": "crates/router/src/db/merchant_connector_account.rs::trait::ConnectorAccessToken",
46
+ "file": "crates/router/src/db/merchant_connector_account.rs",
47
+ "kind": "trait_item",
48
+ "status": "modified",
49
+ "code_changed": true,
50
+ "imports_changed": false,
51
+ "before_code": "pub trait ConnectorAccessToken {\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n ) -> CustomResult<(), errors::StorageError>;\n}",
52
+ "after_code": "pub trait ConnectorAccessToken {\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}",
53
+ "diff_span": {
54
+ "before": "",
55
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError>;\n\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError>;\n}"
56
+ },
57
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
58
+ },
59
+ {
60
+ "id": "crates/router/src/db/merchant_connector_account.rs::impl::Store",
61
+ "file": "crates/router/src/db/merchant_connector_account.rs",
62
+ "kind": "impl_item",
63
+ "status": "modified",
64
+ "code_changed": true,
65
+ "imports_changed": false,
66
+ "before_code": "impl ConnectorAccessToken for Store {\n #[instrument(skip_all)]\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }\n}",
67
+ "after_code": "impl ConnectorAccessToken for Store {\n #[instrument(skip_all)]\n async fn get_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }\n}",
68
+ "diff_span": {
69
+ "before": "",
70
+ "after": " merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n //TODO: Handle race condition\n // This function should acquire a global lock on some resource, if access token is already\n // being refreshed by other request then wait till it finishes and use the same access token\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n\n let maybe_token = self\n .get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .get_key::<Option<Vec<u8>>>(&key.into())\n .await\n .change_context(errors::StorageError::KVError)\n .attach_printable(\"DB error when getting access token\")?;\n\n let access_token = maybe_token\n .map(|token| token.parse_struct::<types::AccessToken>(\"AccessToken\"))\n .transpose()\n .change_context(errors::StorageError::DeserializationFailed)?;\n\n Ok(access_token)\n }\n\n #[instrument(skip_all)]\n async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token"
71
+ },
72
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
73
+ },
74
+ {
75
+ "id": "crates/router/src/db/merchant_connector_account.rs::impl::MockDb",
76
+ "file": "crates/router/src/db/merchant_connector_account.rs",
77
+ "kind": "impl_item",
78
+ "status": "modified",
79
+ "code_changed": true,
80
+ "imports_changed": false,
81
+ "before_code": "impl ConnectorAccessToken for MockDb {\n async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }\n}",
82
+ "after_code": "impl ConnectorAccessToken for MockDb {\n async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }\n}",
83
+ "diff_span": {
84
+ "before": "",
85
+ "after": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }\n\n async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())"
86
+ },
87
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
88
+ },
89
+ {
90
+ "id": "crates/router/src/db/merchant_connector_account.rs::MockDb::function::get_access_token",
91
+ "file": "crates/router/src/db/merchant_connector_account.rs",
92
+ "kind": "function_item",
93
+ "status": "modified",
94
+ "code_changed": true,
95
+ "imports_changed": false,
96
+ "before_code": "async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }",
97
+ "after_code": "async fn get_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)\n }",
98
+ "diff_span": {
99
+ "before": "",
100
+ "after": " _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _payment_method_type: Option<String>,\n ) -> CustomResult<Option<types::AccessToken>, errors::StorageError> {\n Ok(None)"
101
+ },
102
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
103
+ },
104
+ {
105
+ "id": "crates/common_utils/src/access_token.rs::function::create_access_token_key",
106
+ "file": "crates/common_utils/src/access_token.rs",
107
+ "kind": "function_item",
108
+ "status": "modified",
109
+ "code_changed": true,
110
+ "imports_changed": false,
111
+ "before_code": "pub fn create_access_token_key(\n merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name)\n}",
112
+ "after_code": "pub fn create_access_token_key(\n merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name, payment_method_type)\n}",
113
+ "diff_span": {
114
+ "before": " merchant_connector_id_or_connector_name: impl Display,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name)\n}",
115
+ "after": " merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n) -> String {\n merchant_id.get_access_token_key(merchant_connector_id_or_connector_name, payment_method_type)\n}"
116
+ },
117
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
118
+ },
119
+ {
120
+ "id": "crates/router/src/core/payments/access_token.rs::function::add_access_token",
121
+ "file": "crates/router/src/core/payments/access_token.rs",
122
+ "kind": "function_item",
123
+ "status": "modified",
124
+ "code_changed": true,
125
+ "imports_changed": false,
126
+ "before_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let old_access_token = store\n .get_access_token(merchant_id, &merchant_connector_id_or_connector_name)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
127
+ "after_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let pmt_suffix = connector\n .connector_name\n .is_different_access_token_required_per_payment_method_type()\n .then(|| {\n router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string())\n })\n .flatten();\n\n let old_access_token = store\n .get_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n modified_access_token_with_expiry.clone(),\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
128
+ "diff_span": {
129
+ "before": "\n let old_access_token = store\n .get_access_token(merchant_id, &merchant_connector_id_or_connector_name)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)",
130
+ "after": " .unwrap_or(connector.connector_name.to_string());\n\n let pmt_suffix = connector\n .connector_name\n .is_different_access_token_required_per_payment_method_type()\n .then(|| {\n router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string())\n })\n .flatten();\n\n let old_access_token = store\n .get_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n modified_access_token_with_expiry.clone(),\n pmt_suffix.clone(),\n )\n .await"
131
+ },
132
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
133
+ },
134
+ {
135
+ "id": "crates/router/src/db/kafka_store.rs::KafkaStore::function::get_access_token",
136
+ "file": "crates/router/src/db/kafka_store.rs",
137
+ "kind": "function_item",
138
+ "status": "modified",
139
+ "code_changed": true,
140
+ "imports_changed": false,
141
+ "before_code": "async fn get_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id)\n .await\n }",
142
+ "after_code": "async fn get_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id, payment_method_type)\n .await\n }",
143
+ "diff_span": {
144
+ "before": " ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id)\n .await\n }",
145
+ "after": " merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n payment_method_type: Option<String>,\n ) -> CustomResult<Option<AccessToken>, errors::StorageError> {\n self.diesel_store\n .get_access_token(merchant_id, merchant_connector_id, payment_method_type)\n .await\n }"
146
+ },
147
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
148
+ },
149
+ {
150
+ "id": "crates/common_utils/src/id_type/merchant.rs::impl::MerchantId",
151
+ "file": "crates/common_utils/src/id_type/merchant.rs",
152
+ "kind": "impl_item",
153
+ "status": "modified",
154
+ "code_changed": true,
155
+ "imports_changed": false,
156
+ "before_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}\",\n self.get_string_repr()\n )\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
157
+ "after_code": "impl MerchantId {\n /// get step up enabled key\n pub fn get_step_up_enabled_key(&self) -> String {\n format!(\"step_up_enabled_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_retries_enabled key\n pub fn get_max_auto_retries_enabled(&self) -> String {\n format!(\"max_auto_retries_enabled_{}\", self.get_string_repr())\n }\n\n /// get_requires_cvv_key\n pub fn get_requires_cvv_key(&self) -> String {\n format!(\"{}_requires_cvv\", self.get_string_repr())\n }\n\n /// get_pm_filters_cgraph_key\n pub fn get_pm_filters_cgraph_key(&self) -> String {\n format!(\"pm_filters_cgraph_{}\", self.get_string_repr())\n }\n\n /// get_blocklist_enabled_key\n pub fn get_blocklist_guard_key(&self) -> String {\n format!(\"guard_blocklist_for_{}\", self.get_string_repr())\n }\n\n /// get_merchant_fingerprint_secret_key\n pub fn get_merchant_fingerprint_secret_key(&self) -> String {\n format!(\"fingerprint_secret_{}\", self.get_string_repr())\n }\n\n /// get_surcharge_dsk_key\n pub fn get_surcharge_dsk_key(&self) -> String {\n format!(\"surcharge_dsl_{}\", self.get_string_repr())\n }\n\n /// get_dsk_key\n pub fn get_dsl_config(&self) -> String {\n format!(\"dsl_{}\", self.get_string_repr())\n }\n\n /// get_creds_identifier_key\n pub fn get_creds_identifier_key(&self, creds_identifier: &str) -> String {\n format!(\"mcd_{}_{creds_identifier}\", self.get_string_repr())\n }\n\n /// get_poll_id\n pub fn get_poll_id(&self, unique_id: &str) -> String {\n format!(\"poll_{}_{unique_id}\", self.get_string_repr())\n }\n\n /// get_access_token_key\n pub fn get_access_token_key(\n &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }\n\n /// get_skip_saving_wallet_at_connector_key\n pub fn get_skip_saving_wallet_at_connector_key(&self) -> String {\n format!(\"skip_saving_wallet_at_connector_{}\", self.get_string_repr())\n }\n\n /// get_payment_config_routing_id\n pub fn get_payment_config_routing_id(&self) -> String {\n format!(\"payment_config_id_{}\", self.get_string_repr())\n }\n\n /// get_payment_method_surcharge_routing_id\n pub fn get_payment_method_surcharge_routing_id(&self) -> String {\n format!(\"payment_method_surcharge_id_{}\", self.get_string_repr())\n }\n\n /// get_webhook_config_disabled_events_key\n pub fn get_webhook_config_disabled_events_key(&self, connector_id: &str) -> String {\n format!(\n \"whconf_disabled_events_{}_{connector_id}\",\n self.get_string_repr()\n )\n }\n\n /// get_should_call_gsm_payout_key\n pub fn get_should_call_gsm_payout_key(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"should_call_gsm_single_connector_payout_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"should_call_gsm_multiple_connector_payout_{}\",\n self.get_string_repr()\n ),\n }\n }\n\n /// Get should call gsm key for payment\n pub fn get_should_call_gsm_key(&self) -> String {\n format!(\"should_call_gsm_{}\", self.get_string_repr())\n }\n\n /// get_max_auto_single_connector_payout_retries_enabled_\n pub fn get_max_auto_single_connector_payout_retries_enabled(\n &self,\n payout_retry_type: common_enums::PayoutRetryType,\n ) -> String {\n match payout_retry_type {\n common_enums::PayoutRetryType::SingleConnector => format!(\n \"max_auto_single_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n common_enums::PayoutRetryType::MultiConnector => format!(\n \"max_auto_multiple_connector_payout_retries_enabled_{}\",\n self.get_string_repr()\n ),\n }\n }\n /// allow payment update via client auth default should be false\n pub fn get_payment_update_enabled_for_client_auth_key(&self) -> String {\n format!(\n \"payment_update_enabled_for_client_auth_{}\",\n self.get_string_repr()\n )\n }\n\n /// Get should perform eligibility check key for payment\n pub fn get_should_perform_eligibility_check_key(&self) -> String {\n format!(\"should_perform_eligibility_{}\", self.get_string_repr())\n }\n}",
158
+ "diff_span": {
159
+ "before": " ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}\",\n self.get_string_repr()\n )\n }",
160
+ "after": " &self,\n merchant_connector_id_or_connector_name: impl Display,\n payment_method_type: Option<String>,\n ) -> String {\n format!(\n \"access_token_{}_{merchant_connector_id_or_connector_name}_{:?}\",\n self.get_string_repr(),\n payment_method_type,\n )\n }"
161
+ },
162
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
163
+ },
164
+ {
165
+ "id": "crates/router/src/db/kafka_store.rs::KafkaStore::function::set_access_token",
166
+ "file": "crates/router/src/db/kafka_store.rs",
167
+ "kind": "function_item",
168
+ "status": "modified",
169
+ "code_changed": true,
170
+ "imports_changed": false,
171
+ "before_code": "async fn set_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token: AccessToken,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(merchant_id, merchant_connector_id, access_token)\n .await\n }",
172
+ "after_code": "async fn set_access_token(\n &self,\n merchant_id: &id_type::MerchantId,\n merchant_connector_id: &str,\n access_token: AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n payment_method_type,\n )\n .await\n }",
173
+ "diff_span": {
174
+ "before": " ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(merchant_id, merchant_connector_id, access_token)\n .await\n }",
175
+ "after": " merchant_connector_id: &str,\n access_token: AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n self.diesel_store\n .set_access_token(\n merchant_id,\n merchant_connector_id,\n access_token,\n payment_method_type,\n )\n .await\n }"
176
+ },
177
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
178
+ },
179
+ {
180
+ "id": "crates/router/src/db/merchant_connector_account.rs::MockDb::function::set_access_token",
181
+ "file": "crates/router/src/db/merchant_connector_account.rs",
182
+ "kind": "function_item",
183
+ "status": "modified",
184
+ "code_changed": true,
185
+ "imports_changed": false,
186
+ "before_code": "async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }",
187
+ "after_code": "async fn set_access_token(\n &self,\n _merchant_id: &common_utils::id_type::MerchantId,\n _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())\n }",
188
+ "diff_span": {
189
+ "before": "",
190
+ "after": " _merchant_connector_id_or_connector_name: &str,\n _access_token: types::AccessToken,\n _payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n Ok(())"
191
+ },
192
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
193
+ },
194
+ {
195
+ "id": "crates/router/src/core/payouts/access_token.rs::function::add_access_token_for_payout",
196
+ "file": "crates/router/src/core/payouts/access_token.rs",
197
+ "kind": "function_item",
198
+ "status": "modified",
199
+ "code_changed": true,
200
+ "imports_changed": false,
201
+ "before_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n use crate::types::api::ConnectorCommon;\n\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let merchant_id = merchant_context.get_merchant_account().get_id();\n let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(\n merchant_id,\n connector.connector.id(),\n access_token.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
202
+ "after_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n use crate::types::api::ConnectorCommon;\n\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let merchant_id = merchant_context.get_merchant_account().get_id();\n let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id(), None)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(\n merchant_id,\n connector.connector.id(),\n access_token.clone(),\n None,\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
203
+ "diff_span": {
204
+ "before": " let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)",
205
+ "after": " let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id(), None)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(\n merchant_id,\n connector.connector.id(),\n access_token.clone(),\n None,\n )\n .await"
206
+ },
207
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
208
+ },
209
+ {
210
+ "id": "crates/router/src/db/merchant_connector_account.rs::Store::function::set_access_token",
211
+ "file": "crates/router/src/db/merchant_connector_account.rs",
212
+ "kind": "function_item",
213
+ "status": "modified",
214
+ "code_changed": true,
215
+ "imports_changed": false,
216
+ "before_code": "async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }",
217
+ "after_code": "async fn set_access_token(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token\n .encode_to_string_of_json()\n .change_context(errors::StorageError::SerializationFailed)?;\n self.get_redis_conn()\n .map_err(Into::<errors::StorageError>::into)?\n .set_key_with_expiry(&key.into(), serialized_access_token, access_token.expires)\n .await\n .change_context(errors::StorageError::KVError)\n }",
218
+ "diff_span": {
219
+ "before": "",
220
+ "after": " merchant_connector_id_or_connector_name: &str,\n access_token: types::AccessToken,\n payment_method_type: Option<String>,\n ) -> CustomResult<(), errors::StorageError> {\n let key = common_utils::access_token::create_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n payment_method_type,\n );\n let serialized_access_token = access_token"
221
+ },
222
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
223
+ },
224
+ {
225
+ "id": "crates/common_enums/src/connector_enums.rs::Connector::function::is_different_access_token_required_per_payment_method_type",
226
+ "file": "crates/common_enums/src/connector_enums.rs",
227
+ "kind": "function_item",
228
+ "status": "added",
229
+ "before_code": null,
230
+ "after_code": "pub fn is_different_access_token_required_per_payment_method_type(self) -> bool {\n matches!(self, Self::Santander)\n }",
231
+ "diff_span": null,
232
+ "commit_sha": "28781e8f64e4a1eb47d0308de4e561fba41d52f2"
233
+ }
234
+ ]
235
+ }
diffs/pr_10080/2bfa3fc/diff.json ADDED
The diff for this file is too large to render. See raw diff
 
diffs/pr_10080/40ff6f2/diff.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "40ff6f2b5764a9b8bd2a159047248fdac3c00455",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
6
+ "crates/router/src/core/payments/access_token.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/router/src/core/payments/access_token.rs::function::add_access_token",
11
+ "file": "crates/router/src/core/payments/access_token.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": false,
16
+ "before_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name.clone(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!(\n \"Failed to get access token key for connector: {:?}\",\n connector.connector_name\n ))?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
17
+ "after_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(router_data, merchant_connector_id_or_connector_name.clone())\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!(\n \"Failed to get access token key for connector: {:?}\",\n connector.connector_name\n ))?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
18
+ "diff_span": {
19
+ "before": " .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name.clone(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!(",
20
+ "after": " .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key(router_data, merchant_connector_id_or_connector_name.clone())\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(format!("
21
+ },
22
+ "commit_sha": "40ff6f2b5764a9b8bd2a159047248fdac3c00455"
23
+ },
24
+ {
25
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_key",
26
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
27
+ "kind": "function_item",
28
+ "status": "modified",
29
+ "code_changed": true,
30
+ "imports_changed": false,
31
+ "before_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
32
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => {\n connector.get_access_token_key(router_data, merchant_connector_id_or_connector_name)\n }\n Self::New(connector) => {\n connector.get_access_token_key(router_data, merchant_connector_id_or_connector_name)\n }\n }\n }",
33
+ "diff_span": {
34
+ "before": " ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_key(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
35
+ "after": " ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => {\n connector.get_access_token_key(router_data, merchant_connector_id_or_connector_name)\n }\n Self::New(connector) => {\n connector.get_access_token_key(router_data, merchant_connector_id_or_connector_name)\n }\n }\n }"
36
+ },
37
+ "commit_sha": "40ff6f2b5764a9b8bd2a159047248fdac3c00455"
38
+ }
39
+ ]
40
+ }
diffs/pr_10080/57fa606/diff.json ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/common_utils/src/access_token.rs",
6
+ "crates/common_utils/src/lib.rs",
7
+ "crates/hyperswitch_connectors/src/connectors/santander.rs",
8
+ "crates/hyperswitch_interfaces/src/api.rs",
9
+ "crates/router/src/core/payment_methods/access_token.rs",
10
+ "crates/router/src/core/payments/access_token.rs",
11
+ "crates/router/src/core/payouts/access_token.rs",
12
+ "crates/router/src/core/unified_connector_service.rs"
13
+ ],
14
+ "diffs": [
15
+ {
16
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorAccessTokenSuffix",
17
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
18
+ "kind": "trait_item",
19
+ "status": "modified",
20
+ "code_changed": true,
21
+ "imports_changed": false,
22
+ "before_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
23
+ "after_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n ))\n }\n}",
24
+ "diff_span": {
25
+ "before": " merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
26
+ "after": " merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n ))\n }"
27
+ },
28
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
29
+ },
30
+ {
31
+ "id": "crates/router/src/core/payment_methods/access_token.rs::function::add_access_token_for_external_vault",
32
+ "file": "crates/router/src/core/payment_methods/access_token.rs",
33
+ "kind": "function_item",
34
+ "status": "modified",
35
+ "code_changed": true,
36
+ "imports_changed": false,
37
+ "before_code": "pub async fn add_access_token_for_external_vault<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_account: &domain::MerchantAccount,\n router_data: &VaultRouterData<F>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_external_vault()\n {\n let merchant_id = merchant_account.get_id();\n let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(\n merchant_id,\n connector.connector.id(),\n access_token.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
38
+ "after_code": "pub async fn add_access_token_for_external_vault<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_account: &domain::MerchantAccount,\n router_data: &VaultRouterData<F>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_external_vault()\n {\n let merchant_id = merchant_account.get_id();\n let store = &*state.store;\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n connector.connector.id(),\n );\n let old_access_token = store\n .get_access_token(key)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n connector.connector.id(),\n );\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
39
+ "diff_span": {
40
+ "before": " let store = &*state.store;\n let old_access_token = store\n .get_access_token(merchant_id, connector.connector.id())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(\n merchant_id,\n connector.connector.id(),\n access_token.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)",
41
+ "after": " let merchant_id = merchant_account.get_id();\n let store = &*state.store;\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n connector.connector.id(),\n );\n let old_access_token = store\n .get_access_token(key)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n connector.connector.id(),\n );\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)"
42
+ },
43
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
44
+ },
45
+ {
46
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::impl::Santander",
47
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
48
+ "kind": "impl_item",
49
+ "status": "modified",
50
+ "code_changed": true,
51
+ "imports_changed": false,
52
+ "before_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }\n}",
53
+ "after_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n )),\n }\n }\n}",
54
+ "diff_span": {
55
+ "before": " key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }",
56
+ "after": " key\n )),\n None => Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n )),\n }"
57
+ },
58
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
59
+ },
60
+ {
61
+ "id": "crates/router/src/core/payouts/access_token.rs::function::add_access_token_for_payout",
62
+ "file": "crates/router/src/core/payouts/access_token.rs",
63
+ "kind": "function_item",
64
+ "status": "modified",
65
+ "code_changed": true,
66
+ "imports_changed": false,
67
+ "before_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n platform: &domain::Platform,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let merchant_id = platform.get_processor().get_account().get_id();\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, platform, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
68
+ "after_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n platform: &domain::Platform,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, platform, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
69
+ "diff_span": {
70
+ "before": " .supports_access_token_for_payout(payout_type)\n {\n let merchant_id = platform.get_processor().get_account().get_id();\n let store = &*state.store;\n",
71
+ "after": ""
72
+ },
73
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
74
+ },
75
+ {
76
+ "id": "crates/hyperswitch_interfaces/src/api.rs::ConnectorAccessTokenSuffix::function::get_access_token_key",
77
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
78
+ "kind": "function_item",
79
+ "status": "modified",
80
+ "code_changed": true,
81
+ "imports_changed": false,
82
+ "before_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
83
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n ))\n }",
84
+ "diff_span": {
85
+ "before": " merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
86
+ "after": " merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n ))\n }"
87
+ },
88
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
89
+ },
90
+ {
91
+ "id": "crates/router/src/core/unified_connector_service.rs::function::set_access_token_for_ucs",
92
+ "file": "crates/router/src/core/unified_connector_service.rs",
93
+ "kind": "function_item",
94
+ "status": "modified",
95
+ "code_changed": true,
96
+ "imports_changed": false,
97
+ "before_code": "pub async fn set_access_token_for_ucs(\n state: &SessionState,\n platform: &Platform,\n connector_name: &str,\n access_token: AccessToken,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n) -> Result<(), errors::StorageError> {\n let merchant_id = platform.get_processor().get_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n\n let modified_access_token = AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification = modified_access_token.expires,\n merchant_id = ?merchant_id,\n connector_name = connector_name,\n merchant_connector_id_or_connector_name = merchant_connector_id_or_connector_name\n );\n\n if let Err(access_token_set_error) = state\n .store\n .set_access_token(key, modified_access_token)\n .await\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error, \"Failed to store UCS access token\");\n }\n\n Ok(())\n}",
98
+ "after_code": "pub async fn set_access_token_for_ucs(\n state: &SessionState,\n platform: &Platform,\n connector_name: &str,\n access_token: AccessToken,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n) -> Result<(), errors::StorageError> {\n let merchant_id = platform.get_processor().get_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n );\n\n let modified_access_token = AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification = modified_access_token.expires,\n merchant_id = ?merchant_id,\n connector_name = connector_name,\n merchant_connector_id_or_connector_name = merchant_connector_id_or_connector_name\n );\n\n if let Err(access_token_set_error) = state\n .store\n .set_access_token(key, modified_access_token)\n .await\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error, \"Failed to store UCS access token\");\n }\n\n Ok(())\n}",
99
+ "diff_span": {
100
+ "before": " .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n",
101
+ "after": " .unwrap_or(connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n );\n"
102
+ },
103
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
104
+ },
105
+ {
106
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::get_access_token_key",
107
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
108
+ "kind": "function_item",
109
+ "status": "modified",
110
+ "code_changed": true,
111
+ "imports_changed": false,
112
+ "before_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }",
113
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n )),\n }\n }",
114
+ "diff_span": {
115
+ "before": " key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }",
116
+ "after": " key\n )),\n None => Ok(common_utils::access_token::get_default_access_token_key(\n &router_data.merchant_id,\n merchant_connector_id_or_connector_name,\n )),\n }"
117
+ },
118
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
119
+ },
120
+ {
121
+ "id": "crates/router/src/core/payments/access_token.rs::function::get_cached_access_token_for_ucs",
122
+ "file": "crates/router/src/core/payments/access_token.rs",
123
+ "kind": "function_item",
124
+ "status": "modified",
125
+ "code_changed": true,
126
+ "imports_changed": false,
127
+ "before_code": "pub async fn get_cached_access_token_for_ucs(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n platform: &domain::Platform,\n payment_method: common_enums::PaymentMethod,\n creds_identifier: Option<&str>,\n) -> RouterResult<Option<types::AccessToken>> {\n if connector\n .connector_name\n .supports_access_token(payment_method)\n {\n let merchant_id = platform.get_processor().get_account().get_id();\n let store = &*state.store;\n\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n\n let cached_access_token = store\n .get_access_token(key)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n if let Some(access_token) = cached_access_token {\n router_env::logger::info!(\n \"Cached access token found for UCS flow - merchant_id: {:?}, connector: {} with expiry of: {} seconds\",\n platform.get_processor().get_account().get_id(),\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\"connector\", connector.connector_name.to_string())),\n );\n Ok(Some(access_token))\n } else {\n router_env::logger::info!(\n \"No cached access token found for UCS flow - UCS will generate internally - merchant_id: {:?}, connector: {}\",\n platform.get_processor().get_account().get_id(),\n connector.connector_name\n );\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\"connector\", connector.connector_name.to_string())),\n );\n Ok(None)\n }\n } else {\n Ok(None)\n }\n}",
128
+ "after_code": "pub async fn get_cached_access_token_for_ucs(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n platform: &domain::Platform,\n payment_method: common_enums::PaymentMethod,\n creds_identifier: Option<&str>,\n) -> RouterResult<Option<types::AccessToken>> {\n if connector\n .connector_name\n .supports_access_token(payment_method)\n {\n let merchant_id = platform.get_processor().get_account().get_id();\n let store = &*state.store;\n\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n\n let cached_access_token = store\n .get_access_token(key)\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n if let Some(access_token) = cached_access_token {\n router_env::logger::info!(\n \"Cached access token found for UCS flow - merchant_id: {:?}, connector: {} with expiry of: {} seconds\",\n platform.get_processor().get_account().get_id(),\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\"connector\", connector.connector_name.to_string())),\n );\n Ok(Some(access_token))\n } else {\n router_env::logger::info!(\n \"No cached access token found for UCS flow - UCS will generate internally - merchant_id: {:?}, connector: {}\",\n platform.get_processor().get_account().get_id(),\n connector.connector_name\n );\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\"connector\", connector.connector_name.to_string())),\n );\n Ok(None)\n }\n } else {\n Ok(None)\n }\n}",
129
+ "diff_span": {
130
+ "before": " .unwrap_or(connector.connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n",
131
+ "after": " .unwrap_or(connector.connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n"
132
+ },
133
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
134
+ },
135
+ {
136
+ "id": "crates/router/src/core/unified_connector_service.rs::function::get_access_token_from_ucs_response",
137
+ "file": "crates/router/src/core/unified_connector_service.rs",
138
+ "kind": "function_item",
139
+ "status": "modified",
140
+ "code_changed": true,
141
+ "imports_changed": false,
142
+ "before_code": "pub async fn get_access_token_from_ucs_response(\n session_state: &SessionState,\n platform: &Platform,\n connector_name: &str,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n ucs_state: Option<&unified_connector_service_client::payments::ConnectorState>,\n) -> Option<AccessToken> {\n let ucs_access_token = ucs_state\n .and_then(|state| state.access_token.as_ref())\n .map(AccessToken::foreign_from)?;\n\n let merchant_id = platform.get_processor().get_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n\n if let Ok(Some(cached_token)) = session_state.store.get_access_token(key).await {\n if cached_token.token.peek() == ucs_access_token.token.peek() {\n return None;\n }\n }\n\n Some(ucs_access_token)\n}",
143
+ "after_code": "pub async fn get_access_token_from_ucs_response(\n session_state: &SessionState,\n platform: &Platform,\n connector_name: &str,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n ucs_state: Option<&unified_connector_service_client::payments::ConnectorState>,\n) -> Option<AccessToken> {\n let ucs_access_token = ucs_state\n .and_then(|state| state.access_token.as_ref())\n .map(AccessToken::foreign_from)?;\n\n let merchant_id = platform.get_processor().get_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n\n if let Ok(Some(cached_token)) = session_state.store.get_access_token(key).await {\n if cached_token.token.peek() == ucs_access_token.token.peek() {\n return None;\n }\n }\n\n Some(ucs_access_token)\n}",
144
+ "diff_span": {
145
+ "before": " .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n",
146
+ "after": " .unwrap_or(connector_name.to_string());\n\n let key = common_utils::access_token::get_default_access_token_key(\n merchant_id,\n merchant_connector_id_or_connector_name,\n );\n"
147
+ },
148
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
149
+ },
150
+ {
151
+ "id": "crates/common_utils/src/lib.rs::mod::access_token",
152
+ "file": "crates/common_utils/src/lib.rs",
153
+ "kind": "mod_item",
154
+ "status": "added",
155
+ "before_code": null,
156
+ "after_code": "pub mod access_token;",
157
+ "diff_span": null,
158
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
159
+ },
160
+ {
161
+ "id": "crates/common_utils/src/access_token.rs::function::get_default_access_token_key",
162
+ "file": "crates/common_utils/src/access_token.rs",
163
+ "kind": "function_item",
164
+ "status": "added",
165
+ "before_code": null,
166
+ "after_code": "pub fn get_default_access_token_key(\n merchant_id: &id_type::MerchantId,\n merchant_connector_id_or_connector_name: impl Display,\n) -> String {\n format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )\n}",
167
+ "diff_span": null,
168
+ "commit_sha": "57fa606ea2d0766acbe4d917d5d1dd350d7928d5"
169
+ }
170
+ ]
171
+ }
diffs/pr_10080/7959c36/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "7959c36da9de19170c9a621676bc44039b13af3a",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/router/src/core/unified_connector_service.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/router/src/core/unified_connector_service.rs::function::set_access_token_for_ucs",
10
+ "file": "crates/router/src/core/unified_connector_service.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "pub async fn set_access_token_for_ucs(\n state: &SessionState,\n merchant_context: &MerchantContext,\n connector_name: &str,\n access_token: AccessToken,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n) -> Result<(), errors::StorageError> {\n let merchant_id = merchant_context.get_merchant_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n\n let modified_access_token = AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification = modified_access_token.expires,\n merchant_id = ?merchant_id,\n connector_name = connector_name,\n merchant_connector_id_or_connector_name = merchant_connector_id_or_connector_name\n );\n\n if let Err(access_token_set_error) = state\n .store\n .set_access_token(\n key,\n // merchant_id,\n // &merchant_connector_id_or_connector_name,\n modified_access_token,\n // None,\n )\n .await\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error, \"Failed to store UCS access token\");\n }\n\n Ok(())\n}",
16
+ "after_code": "pub async fn set_access_token_for_ucs(\n state: &SessionState,\n merchant_context: &MerchantContext,\n connector_name: &str,\n access_token: AccessToken,\n merchant_connector_id: Option<&id_type::MerchantConnectorAccountId>,\n creds_identifier: Option<String>,\n) -> Result<(), errors::StorageError> {\n let merchant_id = merchant_context.get_merchant_account().get_id();\n\n let merchant_connector_id_or_connector_name = merchant_connector_id\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector_name.to_string());\n\n let key = format!(\n \"access_token_{}_{}\",\n merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n );\n\n let modified_access_token = AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification = modified_access_token.expires,\n merchant_id = ?merchant_id,\n connector_name = connector_name,\n merchant_connector_id_or_connector_name = merchant_connector_id_or_connector_name\n );\n\n if let Err(access_token_set_error) = state\n .store\n .set_access_token(key, modified_access_token)\n .await\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error, \"Failed to store UCS access token\");\n }\n\n Ok(())\n}",
17
+ "diff_span": {
18
+ "before": " if let Err(access_token_set_error) = state\n .store\n .set_access_token(\n key,\n // merchant_id,\n // &merchant_connector_id_or_connector_name,\n modified_access_token,\n // None,\n )\n .await\n {",
19
+ "after": " if let Err(access_token_set_error) = state\n .store\n .set_access_token(key, modified_access_token)\n .await\n {"
20
+ },
21
+ "commit_sha": "7959c36da9de19170c9a621676bc44039b13af3a"
22
+ }
23
+ ]
24
+ }
diffs/pr_10080/979147e/diff.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "979147ef8ee64325c4aea5fe6fce9f28f3239173",
3
+ "pr_number": 10080,
4
+ "rust_files": [],
5
+ "diffs": []
6
+ }
diffs/pr_10080/9e04455/diff.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "9e044556800ed5582b33230b316688c077c34557",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_connectors/src/connectors/santander.rs",
6
+ "crates/hyperswitch_interfaces/src/api.rs",
7
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs"
8
+ ],
9
+ "diffs": [
10
+ {
11
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorSpecifications",
12
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
13
+ "kind": "trait_item",
14
+ "status": "modified",
15
+ "code_changed": true,
16
+ "imports_changed": false,
17
+ "before_code": "pub trait ConnectorSpecifications {\n /// Preprocessing flow name if any, that must be made before the current flow.\n fn get_preprocessing_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<PreProcessingFlowName> {\n None\n }\n /// Based on the current flow and preprocessing_flow_response, decide if the main flow must be called or not\n ///\n /// By default, always continue with the main flow after the preprocessing flow.\n fn decide_should_continue_after_preprocessing(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n _pre_processing_flow_name: PreProcessingFlowName,\n _preprocessing_flow_response: PreProcessingFlowResponse<'_>,\n ) -> bool {\n true\n }\n /// If Some is returned, the returned api flow must be made instead of the current flow.\n fn get_alternate_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<AlternateFlow> {\n None\n }\n /// Details related to payment method supported by the connector\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n None\n }\n\n /// Supported webhooks flows\n fn get_supported_webhook_flows(&self) -> Option<&'static [EventClass]> {\n None\n }\n\n /// About the connector\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n None\n }\n\n /// Check if connector should make another request to create an access token\n /// Connectors should override this method if they require an authentication token to create a new access token\n fn authentication_token_for_token_creation(&self) -> bool {\n false\n }\n\n /// Check if connector should make another request to create an customer\n /// Connectors should override this method if they require to create a connector customer\n fn should_call_connector_customer(\n &self,\n _payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> bool {\n false\n }\n\n /// Whether SDK session token generation is enabled for this connector\n fn is_sdk_client_token_generation_enabled(&self) -> bool {\n false\n }\n\n /// Payment method types that support SDK session token generation\n fn supported_payment_method_types_for_sdk_client_token_generation(\n &self,\n ) -> Vec<PaymentMethodType> {\n vec![]\n }\n\n /// Validate if SDK session token generation is allowed for given payment method type\n fn validate_sdk_session_token_for_payment_method(\n &self,\n current_core_payment_method_type: &PaymentMethodType,\n ) -> bool {\n self.is_sdk_client_token_generation_enabled()\n && self\n .supported_payment_method_types_for_sdk_client_token_generation()\n .contains(current_core_payment_method_type)\n }\n\n #[cfg(not(feature = \"v2\"))]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n _payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n is_config_enabled_to_send_payment_id_as_connector_request_id: bool,\n ) -> String {\n // Send payment_id if config is enabled for a merchant, else send attempt_id\n if is_config_enabled_to_send_payment_id_as_connector_request_id {\n payment_attempt.payment_id.get_string_repr().to_owned()\n } else {\n payment_attempt.attempt_id.to_owned()\n }\n }\n\n #[cfg(feature = \"v2\")]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> String {\n payment_intent\n .merchant_reference_id\n .as_ref()\n .map(|id| id.get_string_repr().to_owned())\n .unwrap_or_else(|| payment_attempt.id.get_string_repr().to_owned())\n }\n\n /// Check if connector needs tokenization call before setup mandate flow\n fn should_call_tokenization_before_setup_mandate(&self) -> bool {\n true\n }\n\n /// Check if connector requires different access token per payment method type\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }\n}",
18
+ "after_code": "pub trait ConnectorSpecifications {\n /// Preprocessing flow name if any, that must be made before the current flow.\n fn get_preprocessing_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<PreProcessingFlowName> {\n None\n }\n /// Based on the current flow and preprocessing_flow_response, decide if the main flow must be called or not\n ///\n /// By default, always continue with the main flow after the preprocessing flow.\n fn decide_should_continue_after_preprocessing(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n _pre_processing_flow_name: PreProcessingFlowName,\n _preprocessing_flow_response: PreProcessingFlowResponse<'_>,\n ) -> bool {\n true\n }\n /// If Some is returned, the returned api flow must be made instead of the current flow.\n fn get_alternate_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<AlternateFlow> {\n None\n }\n /// Details related to payment method supported by the connector\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n None\n }\n\n /// Supported webhooks flows\n fn get_supported_webhook_flows(&self) -> Option<&'static [EventClass]> {\n None\n }\n\n /// About the connector\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n None\n }\n\n /// Check if connector should make another request to create an access token\n /// Connectors should override this method if they require an authentication token to create a new access token\n fn authentication_token_for_token_creation(&self) -> bool {\n false\n }\n\n /// Check if connector should make another request to create an customer\n /// Connectors should override this method if they require to create a connector customer\n fn should_call_connector_customer(\n &self,\n _payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> bool {\n false\n }\n\n /// Whether SDK session token generation is enabled for this connector\n fn is_sdk_client_token_generation_enabled(&self) -> bool {\n false\n }\n\n /// Payment method types that support SDK session token generation\n fn supported_payment_method_types_for_sdk_client_token_generation(\n &self,\n ) -> Vec<PaymentMethodType> {\n vec![]\n }\n\n /// Validate if SDK session token generation is allowed for given payment method type\n fn validate_sdk_session_token_for_payment_method(\n &self,\n current_core_payment_method_type: &PaymentMethodType,\n ) -> bool {\n self.is_sdk_client_token_generation_enabled()\n && self\n .supported_payment_method_types_for_sdk_client_token_generation()\n .contains(current_core_payment_method_type)\n }\n\n #[cfg(not(feature = \"v2\"))]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n _payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n is_config_enabled_to_send_payment_id_as_connector_request_id: bool,\n ) -> String {\n // Send payment_id if config is enabled for a merchant, else send attempt_id\n if is_config_enabled_to_send_payment_id_as_connector_request_id {\n payment_attempt.payment_id.get_string_repr().to_owned()\n } else {\n payment_attempt.attempt_id.to_owned()\n }\n }\n\n #[cfg(feature = \"v2\")]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> String {\n payment_intent\n .merchant_reference_id\n .as_ref()\n .map(|id| id.get_string_repr().to_owned())\n .unwrap_or_else(|| payment_attempt.id.get_string_repr().to_owned())\n }\n\n /// Check if connector needs tokenization call before setup mandate flow\n fn should_call_tokenization_before_setup_mandate(&self) -> bool {\n true\n }\n}",
19
+ "diff_span": {
20
+ "before": " true\n }\n\n /// Check if connector requires different access token per payment method type\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }\n}",
21
+ "after": ""
22
+ },
23
+ "commit_sha": "9e044556800ed5582b33230b316688c077c34557"
24
+ },
25
+ {
26
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::requires_different_access_token_per_payment_method_type",
27
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
28
+ "kind": "function_item",
29
+ "status": "removed",
30
+ "before_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n true\n }",
31
+ "after_code": null,
32
+ "diff_span": null,
33
+ "commit_sha": "9e044556800ed5582b33230b316688c077c34557"
34
+ },
35
+ {
36
+ "id": "crates/hyperswitch_interfaces/src/api.rs::ConnectorSpecifications::function::requires_different_access_token_per_payment_method_type",
37
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
38
+ "kind": "function_item",
39
+ "status": "removed",
40
+ "before_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }",
41
+ "after_code": null,
42
+ "diff_span": null,
43
+ "commit_sha": "9e044556800ed5582b33230b316688c077c34557"
44
+ },
45
+ {
46
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::requires_different_access_token_per_payment_method_type",
47
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
48
+ "kind": "function_item",
49
+ "status": "removed",
50
+ "before_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n match self {\n Self::Old(connector) => {\n connector.requires_different_access_token_per_payment_method_type()\n }\n Self::New(connector) => {\n connector.requires_different_access_token_per_payment_method_type()\n }\n }\n }",
51
+ "after_code": null,
52
+ "diff_span": null,
53
+ "commit_sha": "9e044556800ed5582b33230b316688c077c34557"
54
+ }
55
+ ]
56
+ }
diffs/pr_10080/aea832f/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "aea832fef0a7853d82f89e7d787239baee4b770c",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/router/src/core/payouts/access_token.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/router/src/core/payouts/access_token.rs::function::add_access_token_for_payout",
10
+ "file": "crates/router/src/core/payouts/access_token.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n connector.connector.id().to_string(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
16
+ "after_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
17
+ "diff_span": {
18
+ "before": " let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n connector.connector.id().to_string(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n",
19
+ "after": " let key = connector\n .connector\n .get_access_token_key_from_connector(router_data, connector.connector.id().to_string())\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n"
20
+ },
21
+ "commit_sha": "aea832fef0a7853d82f89e7d787239baee4b770c"
22
+ }
23
+ ]
24
+ }
diffs/pr_10080/b608274/diff.json ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/common_enums/src/connector_enums.rs",
6
+ "crates/hyperswitch_connectors/src/connectors/santander.rs",
7
+ "crates/hyperswitch_interfaces/src/api.rs",
8
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
9
+ "crates/router/src/core/payments/access_token.rs"
10
+ ],
11
+ "diffs": [
12
+ {
13
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::impl::Santander",
14
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
15
+ "kind": "impl_item",
16
+ "status": "modified",
17
+ "code_changed": true,
18
+ "imports_changed": false,
19
+ "before_code": "impl ConnectorSpecifications for Santander {\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n Some(&SANTANDER_CONNECTOR_INFO)\n }\n\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n Some(&*SANTANDER_SUPPORTED_PAYMENT_METHODS)\n }\n\n fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {\n Some(&SANTANDER_SUPPORTED_WEBHOOK_FLOWS)\n }\n}",
20
+ "after_code": "impl ConnectorSpecifications for Santander {\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n Some(&SANTANDER_CONNECTOR_INFO)\n }\n\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n Some(&*SANTANDER_SUPPORTED_PAYMENT_METHODS)\n }\n\n fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {\n Some(&SANTANDER_SUPPORTED_WEBHOOK_FLOWS)\n }\n\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n true\n }\n}",
21
+ "diff_span": {
22
+ "before": "",
23
+ "after": " Some(&SANTANDER_SUPPORTED_WEBHOOK_FLOWS)\n }\n\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n true\n }\n}"
24
+ },
25
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
26
+ },
27
+ {
28
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorSpecifications",
29
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
30
+ "kind": "trait_item",
31
+ "status": "modified",
32
+ "code_changed": true,
33
+ "imports_changed": false,
34
+ "before_code": "pub trait ConnectorSpecifications {\n /// Preprocessing flow name if any, that must be made before the current flow.\n fn get_preprocessing_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<PreProcessingFlowName> {\n None\n }\n /// Based on the current flow and preprocessing_flow_response, decide if the main flow must be called or not\n ///\n /// By default, always continue with the main flow after the preprocessing flow.\n fn decide_should_continue_after_preprocessing(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n _pre_processing_flow_name: PreProcessingFlowName,\n _preprocessing_flow_response: PreProcessingFlowResponse<'_>,\n ) -> bool {\n true\n }\n /// If Some is returned, the returned api flow must be made instead of the current flow.\n fn get_alternate_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<AlternateFlow> {\n None\n }\n /// Details related to payment method supported by the connector\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n None\n }\n\n /// Supported webhooks flows\n fn get_supported_webhook_flows(&self) -> Option<&'static [EventClass]> {\n None\n }\n\n /// About the connector\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n None\n }\n\n /// Check if connector should make another request to create an access token\n /// Connectors should override this method if they require an authentication token to create a new access token\n fn authentication_token_for_token_creation(&self) -> bool {\n false\n }\n\n /// Check if connector should make another request to create an customer\n /// Connectors should override this method if they require to create a connector customer\n fn should_call_connector_customer(\n &self,\n _payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> bool {\n false\n }\n\n /// Whether SDK session token generation is enabled for this connector\n fn is_sdk_client_token_generation_enabled(&self) -> bool {\n false\n }\n\n /// Payment method types that support SDK session token generation\n fn supported_payment_method_types_for_sdk_client_token_generation(\n &self,\n ) -> Vec<PaymentMethodType> {\n vec![]\n }\n\n /// Validate if SDK session token generation is allowed for given payment method type\n fn validate_sdk_session_token_for_payment_method(\n &self,\n current_core_payment_method_type: &PaymentMethodType,\n ) -> bool {\n self.is_sdk_client_token_generation_enabled()\n && self\n .supported_payment_method_types_for_sdk_client_token_generation()\n .contains(current_core_payment_method_type)\n }\n\n #[cfg(not(feature = \"v2\"))]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n _payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n is_config_enabled_to_send_payment_id_as_connector_request_id: bool,\n ) -> String {\n // Send payment_id if config is enabled for a merchant, else send attempt_id\n if is_config_enabled_to_send_payment_id_as_connector_request_id {\n payment_attempt.payment_id.get_string_repr().to_owned()\n } else {\n payment_attempt.attempt_id.to_owned()\n }\n }\n\n #[cfg(feature = \"v2\")]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> String {\n payment_intent\n .merchant_reference_id\n .as_ref()\n .map(|id| id.get_string_repr().to_owned())\n .unwrap_or_else(|| payment_attempt.id.get_string_repr().to_owned())\n }\n\n /// Check if connector needs tokenization call before setup mandate flow\n fn should_call_tokenization_before_setup_mandate(&self) -> bool {\n true\n }\n}",
35
+ "after_code": "pub trait ConnectorSpecifications {\n /// Preprocessing flow name if any, that must be made before the current flow.\n fn get_preprocessing_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<PreProcessingFlowName> {\n None\n }\n /// Based on the current flow and preprocessing_flow_response, decide if the main flow must be called or not\n ///\n /// By default, always continue with the main flow after the preprocessing flow.\n fn decide_should_continue_after_preprocessing(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n _pre_processing_flow_name: PreProcessingFlowName,\n _preprocessing_flow_response: PreProcessingFlowResponse<'_>,\n ) -> bool {\n true\n }\n /// If Some is returned, the returned api flow must be made instead of the current flow.\n fn get_alternate_flow_if_needed(\n &self,\n _current_flow: CurrentFlowInfo<'_>,\n ) -> Option<AlternateFlow> {\n None\n }\n /// Details related to payment method supported by the connector\n fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {\n None\n }\n\n /// Supported webhooks flows\n fn get_supported_webhook_flows(&self) -> Option<&'static [EventClass]> {\n None\n }\n\n /// About the connector\n fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {\n None\n }\n\n /// Check if connector should make another request to create an access token\n /// Connectors should override this method if they require an authentication token to create a new access token\n fn authentication_token_for_token_creation(&self) -> bool {\n false\n }\n\n /// Check if connector should make another request to create an customer\n /// Connectors should override this method if they require to create a connector customer\n fn should_call_connector_customer(\n &self,\n _payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> bool {\n false\n }\n\n /// Whether SDK session token generation is enabled for this connector\n fn is_sdk_client_token_generation_enabled(&self) -> bool {\n false\n }\n\n /// Payment method types that support SDK session token generation\n fn supported_payment_method_types_for_sdk_client_token_generation(\n &self,\n ) -> Vec<PaymentMethodType> {\n vec![]\n }\n\n /// Validate if SDK session token generation is allowed for given payment method type\n fn validate_sdk_session_token_for_payment_method(\n &self,\n current_core_payment_method_type: &PaymentMethodType,\n ) -> bool {\n self.is_sdk_client_token_generation_enabled()\n && self\n .supported_payment_method_types_for_sdk_client_token_generation()\n .contains(current_core_payment_method_type)\n }\n\n #[cfg(not(feature = \"v2\"))]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n _payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n is_config_enabled_to_send_payment_id_as_connector_request_id: bool,\n ) -> String {\n // Send payment_id if config is enabled for a merchant, else send attempt_id\n if is_config_enabled_to_send_payment_id_as_connector_request_id {\n payment_attempt.payment_id.get_string_repr().to_owned()\n } else {\n payment_attempt.attempt_id.to_owned()\n }\n }\n\n #[cfg(feature = \"v2\")]\n /// Generate connector request reference ID\n fn generate_connector_request_reference_id(\n &self,\n payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,\n payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,\n ) -> String {\n payment_intent\n .merchant_reference_id\n .as_ref()\n .map(|id| id.get_string_repr().to_owned())\n .unwrap_or_else(|| payment_attempt.id.get_string_repr().to_owned())\n }\n\n /// Check if connector needs tokenization call before setup mandate flow\n fn should_call_tokenization_before_setup_mandate(&self) -> bool {\n true\n }\n\n /// Check if connector requires different access token per payment method type\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }\n}",
36
+ "diff_span": {
37
+ "before": "",
38
+ "after": " true\n }\n\n /// Check if connector requires different access token per payment method type\n fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }\n}"
39
+ },
40
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
41
+ },
42
+ {
43
+ "id": "crates/router/src/core/payments/access_token.rs::function::add_access_token",
44
+ "file": "crates/router/src/core/payments/access_token.rs",
45
+ "kind": "function_item",
46
+ "status": "modified",
47
+ "code_changed": true,
48
+ "imports_changed": false,
49
+ "before_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let pmt_suffix = connector\n .connector_name\n .is_different_access_token_required_per_payment_method_type()\n .then(|| {\n router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string())\n })\n .flatten();\n\n let old_access_token = store\n .get_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n modified_access_token_with_expiry.clone(),\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
50
+ "after_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let pmt_suffix = connector\n .connector\n .requires_different_access_token_per_payment_method_type()\n .then(|| {\n router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string())\n })\n .flatten();\n\n let old_access_token = store\n .get_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n merchant_id,\n &merchant_connector_id_or_connector_name,\n modified_access_token_with_expiry.clone(),\n pmt_suffix.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
51
+ "diff_span": {
52
+ "before": "\n let pmt_suffix = connector\n .connector_name\n .is_different_access_token_required_per_payment_method_type()\n .then(|| {\n router_data",
53
+ "after": "\n let pmt_suffix = connector\n .connector\n .requires_different_access_token_per_payment_method_type()\n .then(|| {\n router_data"
54
+ },
55
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
56
+ },
57
+ {
58
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::requires_different_access_token_per_payment_method_type",
59
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
60
+ "kind": "function_item",
61
+ "status": "added",
62
+ "before_code": null,
63
+ "after_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n true\n }",
64
+ "diff_span": null,
65
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
66
+ },
67
+ {
68
+ "id": "crates/hyperswitch_interfaces/src/api.rs::ConnectorSpecifications::function::requires_different_access_token_per_payment_method_type",
69
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
70
+ "kind": "function_item",
71
+ "status": "added",
72
+ "before_code": null,
73
+ "after_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n false\n }",
74
+ "diff_span": null,
75
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
76
+ },
77
+ {
78
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::requires_different_access_token_per_payment_method_type",
79
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
80
+ "kind": "function_item",
81
+ "status": "added",
82
+ "before_code": null,
83
+ "after_code": "fn requires_different_access_token_per_payment_method_type(&self) -> bool {\n match self {\n Self::Old(connector) => {\n connector.requires_different_access_token_per_payment_method_type()\n }\n Self::New(connector) => {\n connector.requires_different_access_token_per_payment_method_type()\n }\n }\n }",
84
+ "diff_span": null,
85
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
86
+ },
87
+ {
88
+ "id": "crates/common_enums/src/connector_enums.rs::Connector::function::is_different_access_token_required_per_payment_method_type",
89
+ "file": "crates/common_enums/src/connector_enums.rs",
90
+ "kind": "function_item",
91
+ "status": "removed",
92
+ "before_code": "pub fn is_different_access_token_required_per_payment_method_type(self) -> bool {\n matches!(self, Self::Santander)\n }",
93
+ "after_code": null,
94
+ "diff_span": null,
95
+ "commit_sha": "b608274faa1e5916c3355ecd4f120cbe8504c575"
96
+ }
97
+ ]
98
+ }
diffs/pr_10080/cb10d10/diff.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "cb10d10cd4353cc9ae5fc889a392c3a2c1ba8d8f",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_connectors/src/connectors/santander.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::impl::Santander",
10
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
11
+ "kind": "impl_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }\n}",
16
+ "after_code": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }\n}",
17
+ "diff_span": {
18
+ "before": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
19
+ "after": "impl ConnectorAccessTokenSuffix for Santander {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
20
+ },
21
+ "commit_sha": "cb10d10cd4353cc9ae5fc889a392c3a2c1ba8d8f"
22
+ },
23
+ {
24
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::get_access_token_key_from_connector",
25
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
26
+ "kind": "function_item",
27
+ "status": "added",
28
+ "before_code": null,
29
+ "after_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }",
30
+ "diff_span": null,
31
+ "commit_sha": "cb10d10cd4353cc9ae5fc889a392c3a2c1ba8d8f"
32
+ },
33
+ {
34
+ "id": "crates/hyperswitch_connectors/src/connectors/santander.rs::Santander::function::get_access_token_suffix_from_connector",
35
+ "file": "crates/hyperswitch_connectors/src/connectors/santander.rs",
36
+ "kind": "function_item",
37
+ "status": "removed",
38
+ "before_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n let key_suffix = router_data\n .payment_method_type\n .as_ref()\n .map(|pmt| pmt.to_string());\n\n match key_suffix {\n Some(key) => Ok(format!(\n \"access_token_{}_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name,\n key\n )),\n None => Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n )),\n }\n }",
39
+ "after_code": null,
40
+ "diff_span": null,
41
+ "commit_sha": "cb10d10cd4353cc9ae5fc889a392c3a2c1ba8d8f"
42
+ }
43
+ ]
44
+ }
diffs/pr_10080/d1cd4a3/diff.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "d1cd4a3591ce8482892fa1901161c97e28f200ad",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
6
+ "crates/hyperswitch_interfaces/src/connector_integration_v2.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_suffix_from_connector",
11
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": false,
16
+ "before_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n ) -> CustomResult<Option<String>, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_suffix_from_connector(router_data),\n Self::New(_connector) => Ok(None),\n }\n }",
17
+ "after_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n ) -> CustomResult<Option<String>, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_suffix_from_connector(router_data),\n Self::New(connector) => connector.get_access_token_suffix_from_connector(router_data),\n }\n }",
18
+ "diff_span": {
19
+ "before": " match self {\n Self::Old(connector) => connector.get_access_token_suffix_from_connector(router_data),\n Self::New(_connector) => Ok(None),\n }\n }",
20
+ "after": " match self {\n Self::Old(connector) => connector.get_access_token_suffix_from_connector(router_data),\n Self::New(connector) => connector.get_access_token_suffix_from_connector(router_data),\n }\n }"
21
+ },
22
+ "commit_sha": "d1cd4a3591ce8482892fa1901161c97e28f200ad"
23
+ },
24
+ {
25
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_suffix_from_connector",
26
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
27
+ "kind": "function_item",
28
+ "status": "added",
29
+ "before_code": null,
30
+ "after_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n _router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n ) -> CustomResult<Option<String>, errors::ConnectorError> {\n Ok(None)\n }",
31
+ "diff_span": null,
32
+ "commit_sha": "d1cd4a3591ce8482892fa1901161c97e28f200ad"
33
+ },
34
+ {
35
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::impl::BoxedConnectorV2",
36
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
37
+ "kind": "impl_item",
38
+ "status": "added",
39
+ "before_code": null,
40
+ "after_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n _router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n ) -> CustomResult<Option<String>, errors::ConnectorError> {\n Ok(None)\n }\n}",
41
+ "diff_span": null,
42
+ "commit_sha": "d1cd4a3591ce8482892fa1901161c97e28f200ad"
43
+ }
44
+ ]
45
+ }
diffs/pr_10080/d93a078/diff.json ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_interfaces/src/api.rs",
6
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
7
+ "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
8
+ "crates/router/src/core/payments/access_token.rs",
9
+ "crates/router/src/core/payouts/access_token.rs"
10
+ ],
11
+ "diffs": [
12
+ {
13
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorAccessTokenSuffix",
14
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
15
+ "kind": "trait_item",
16
+ "status": "modified",
17
+ "code_changed": true,
18
+ "imports_changed": false,
19
+ "before_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
20
+ "after_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
21
+ "diff_span": {
22
+ "before": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
23
+ "after": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
24
+ },
25
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
26
+ },
27
+ {
28
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::impl::BoxedConnectorV2",
29
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
30
+ "kind": "impl_item",
31
+ "status": "modified",
32
+ "code_changed": true,
33
+ "imports_changed": false,
34
+ "before_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
35
+ "after_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
36
+ "diff_span": {
37
+ "before": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,",
38
+ "after": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,"
39
+ },
40
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
41
+ },
42
+ {
43
+ "id": "crates/router/src/core/payments/access_token.rs::function::add_access_token",
44
+ "file": "crates/router/src/core/payments/access_token.rs",
45
+ "kind": "function_item",
46
+ "status": "modified",
47
+ "code_changed": true,
48
+ "imports_changed": false,
49
+ "before_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_suffix_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
50
+ "after_code": "pub async fn add_access_token<\n F: Clone + 'static,\n Req: Debug + Clone + 'static,\n Res: Debug + Clone + 'static,\n>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n router_data: &types::RouterData<F, Req, Res>,\n creds_identifier: Option<&str>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token(router_data.payment_method)\n {\n let merchant_id = &router_data.merchant_id;\n let store = &*state.store;\n\n // `merchant_connector_id` may not be present in the below cases\n // - when straight through routing is used without passing the `merchant_connector_id`\n // - when creds identifier is passed\n //\n // In these cases fallback to `connector_name`.\n // We cannot use multiple merchant connector account in these cases\n let merchant_connector_id_or_connector_name = connector\n .merchant_connector_id\n .clone()\n .map(|mca_id| mca_id.get_string_repr().to_string())\n .or(creds_identifier.map(|id| id.to_string()))\n .unwrap_or(connector.connector_name.to_string());\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => {\n router_env::logger::debug!(\n \"Access token found in redis for merchant_id: {:?}, payment_id: {:?}, connector: {} which has expiry of: {} seconds\",\n merchant_id,\n router_data.payment_id,\n connector.connector_name,\n access_token.expires\n );\n metrics::ACCESS_TOKEN_CACHE_HIT.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n Ok(Some(access_token))\n }\n None => {\n metrics::ACCESS_TOKEN_CACHE_MISS.add(\n 1,\n router_env::metric_attributes!((\n \"connector\",\n connector.connector_name.to_string()\n )),\n );\n\n let authentication_token =\n execute_authentication_token(state, connector, router_data).await?;\n\n let cloned_router_data = router_data.clone();\n\n let refresh_token_request_data = types::AccessTokenRequestData::try_from((\n router_data.connector_auth_type.clone(),\n authentication_token,\n ))\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(state, connector, &refresh_token_router_data)\n .await?\n .async_map(|access_token| async move {\n let store = &*state.store;\n\n // The expiry should be adjusted for network delays from the connector\n // The access token might not have been expired when request is sent\n // But once it reaches the connector, it might expire because of the network delay\n // Subtract few seconds from the expiry in order to account for these network delays\n // This will reduce the expiry time by `REDUCE_ACCESS_TOKEN_EXPIRY_TIME` seconds\n let modified_access_token_with_expiry = types::AccessToken {\n expires: access_token\n .expires\n .saturating_sub(consts::REDUCE_ACCESS_TOKEN_EXPIRY_TIME.into()),\n ..access_token\n };\n\n logger::debug!(\n access_token_expiry_after_modification =\n modified_access_token_with_expiry.expires\n );\n\n if let Err(access_token_set_error) = store\n .set_access_token(\n key.clone(),\n modified_access_token_with_expiry.clone(),\n )\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\")\n {\n // If we are not able to set the access token in redis, the error should just be logged and proceed with the payment\n // Payments should not fail, once the access token is successfully created\n // The next request will create new access token, if required\n logger::error!(access_token_set_error=?access_token_set_error);\n }\n Some(modified_access_token_with_expiry)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
51
+ "diff_span": {
52
+ "before": " let key = connector\n .connector\n .get_access_token_suffix_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,",
53
+ "after": " let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,"
54
+ },
55
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
56
+ },
57
+ {
58
+ "id": "crates/router/src/core/payouts/access_token.rs::function::add_access_token_for_payout",
59
+ "file": "crates/router/src/core/payouts/access_token.rs",
60
+ "kind": "function_item",
61
+ "status": "modified",
62
+ "code_changed": true,
63
+ "imports_changed": false,
64
+ "before_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_suffix_from_connector(\n router_data,\n connector.connector.id().to_string(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
65
+ "after_code": "pub async fn add_access_token_for_payout<F: Clone + 'static>(\n state: &SessionState,\n connector: &api_types::ConnectorData,\n merchant_context: &domain::MerchantContext,\n router_data: &types::PayoutsRouterData<F>,\n payout_type: Option<enums::PayoutType>,\n) -> RouterResult<types::AddAccessTokenResult> {\n if connector\n .connector_name\n .supports_access_token_for_payout(payout_type)\n {\n let store = &*state.store;\n\n let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n connector.connector.id().to_string(),\n )\n .change_context(errors::ApiErrorResponse::InternalServerError)?;\n\n let old_access_token = store\n .get_access_token(key.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when accessing the access token\")?;\n\n let res = match old_access_token {\n Some(access_token) => Ok(Some(access_token)),\n None => {\n let cloned_router_data = router_data.clone();\n let refresh_token_request_data = types::AccessTokenRequestData::try_from(\n router_data.connector_auth_type.clone(),\n )\n .attach_printable(\n \"Could not create access token request, invalid connector account credentials\",\n )?;\n\n let refresh_token_response_data: Result<types::AccessToken, types::ErrorResponse> =\n Err(types::ErrorResponse::default());\n let refresh_token_router_data = payments::helpers::router_data_type_conversion::<\n _,\n api_types::AccessTokenAuth,\n _,\n _,\n _,\n _,\n >(\n cloned_router_data,\n refresh_token_request_data,\n refresh_token_response_data,\n );\n refresh_connector_auth(\n state,\n connector,\n merchant_context,\n &refresh_token_router_data,\n )\n .await?\n .async_map(|access_token| async {\n //Store the access token in db\n let store = &*state.store;\n // This error should not be propagated, we don't want payments to fail once we have\n // the access token, the next request will create new access token\n let _ = store\n .set_access_token(key, access_token.clone())\n .await\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"DB error when setting the access token\");\n Some(access_token)\n })\n .await\n }\n };\n\n Ok(types::AddAccessTokenResult {\n access_token_result: res,\n connector_supports_access_token: true,\n })\n } else {\n Ok(types::AddAccessTokenResult {\n access_token_result: Err(types::ErrorResponse::default()),\n connector_supports_access_token: false,\n })\n }\n}",
66
+ "diff_span": {
67
+ "before": " let key = connector\n .connector\n .get_access_token_suffix_from_connector(\n router_data,\n connector.connector.id().to_string(),",
68
+ "after": " let key = connector\n .connector\n .get_access_token_key_from_connector(\n router_data,\n connector.connector.id().to_string(),"
69
+ },
70
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
71
+ },
72
+ {
73
+ "id": "crates/hyperswitch_interfaces/src/api.rs::impl::BoxedConnector",
74
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
75
+ "kind": "impl_item",
76
+ "status": "modified",
77
+ "code_changed": true,
78
+ "imports_changed": false,
79
+ "before_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
80
+ "after_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
81
+ "diff_span": {
82
+ "before": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,",
83
+ "after": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,"
84
+ },
85
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
86
+ },
87
+ {
88
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_key_from_connector",
89
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
90
+ "kind": "function_item",
91
+ "status": "added",
92
+ "before_code": null,
93
+ "after_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
94
+ "diff_span": null,
95
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
96
+ },
97
+ {
98
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_key_from_connector",
99
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
100
+ "kind": "function_item",
101
+ "status": "added",
102
+ "before_code": null,
103
+ "after_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_key_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
104
+ "diff_span": null,
105
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
106
+ },
107
+ {
108
+ "id": "crates/hyperswitch_interfaces/src/api.rs::BoxedConnector::function::get_access_token_key_from_connector",
109
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
110
+ "kind": "function_item",
111
+ "status": "added",
112
+ "before_code": null,
113
+ "after_code": "fn get_access_token_key_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
114
+ "diff_span": null,
115
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
116
+ },
117
+ {
118
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_access_token_suffix_from_connector",
119
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
120
+ "kind": "function_item",
121
+ "status": "removed",
122
+ "before_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_access_token_suffix_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n Self::New(connector) => connector.get_access_token_suffix_from_connector(\n router_data,\n merchant_connector_id_or_connector_name,\n ),\n }\n }",
123
+ "after_code": null,
124
+ "diff_span": null,
125
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
126
+ },
127
+ {
128
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_suffix_from_connector",
129
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
130
+ "kind": "function_item",
131
+ "status": "removed",
132
+ "before_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
133
+ "after_code": null,
134
+ "diff_span": null,
135
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
136
+ },
137
+ {
138
+ "id": "crates/hyperswitch_interfaces/src/api.rs::BoxedConnector::function::get_access_token_suffix_from_connector",
139
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
140
+ "kind": "function_item",
141
+ "status": "removed",
142
+ "before_code": "fn get_access_token_suffix_from_connector<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
143
+ "after_code": null,
144
+ "diff_span": null,
145
+ "commit_sha": "d93a0780f850bdc07b80ea230fba4c136520b1e7"
146
+ }
147
+ ]
148
+ }
diffs/pr_10080/f238248/diff.json ADDED
The diff for this file is too large to render. See raw diff
 
diffs/pr_10080/f69bde8/diff.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690",
3
+ "pr_number": 10080,
4
+ "rust_files": [
5
+ "crates/hyperswitch_interfaces/src/api.rs",
6
+ "crates/hyperswitch_interfaces/src/connector_integration_v2.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/hyperswitch_interfaces/src/api.rs::trait::ConnectorAccessTokenSuffix",
11
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
12
+ "kind": "trait_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": false,
16
+ "before_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
17
+ "after_code": "pub trait ConnectorAccessTokenSuffix {\n /// Function to get dynamic access token key suffix from Connector\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
18
+ "diff_span": {
19
+ "before": " router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError>;\n}",
20
+ "after": " router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}"
21
+ },
22
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
23
+ },
24
+ {
25
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::impl::BoxedConnectorV2",
26
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
27
+ "kind": "impl_item",
28
+ "status": "modified",
29
+ "code_changed": true,
30
+ "imports_changed": false,
31
+ "before_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
32
+ "after_code": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {}",
33
+ "diff_span": {
34
+ "before": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
35
+ "after": "impl api::ConnectorAccessTokenSuffix for BoxedConnectorV2 {}"
36
+ },
37
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
38
+ },
39
+ {
40
+ "id": "crates/hyperswitch_interfaces/src/api.rs::impl::BoxedConnector",
41
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
42
+ "kind": "impl_item",
43
+ "status": "modified",
44
+ "code_changed": true,
45
+ "imports_changed": false,
46
+ "before_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
47
+ "after_code": "impl ConnectorAccessTokenSuffix for BoxedConnector {}",
48
+ "diff_span": {
49
+ "before": "impl ConnectorAccessTokenSuffix for BoxedConnector {\n fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }\n}",
50
+ "after": "impl ConnectorAccessTokenSuffix for BoxedConnector {}"
51
+ },
52
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
53
+ },
54
+ {
55
+ "id": "crates/hyperswitch_interfaces/src/api.rs::ConnectorAccessTokenSuffix::function::get_access_token_key",
56
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
57
+ "kind": "function_item",
58
+ "status": "added",
59
+ "before_code": null,
60
+ "after_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
61
+ "diff_span": null,
62
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
63
+ },
64
+ {
65
+ "id": "crates/hyperswitch_interfaces/src/api.rs::BoxedConnector::function::get_access_token_key",
66
+ "file": "crates/hyperswitch_interfaces/src/api.rs",
67
+ "kind": "function_item",
68
+ "status": "removed",
69
+ "before_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
70
+ "after_code": null,
71
+ "diff_span": null,
72
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
73
+ },
74
+ {
75
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs::BoxedConnectorV2::function::get_access_token_key",
76
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_v2.rs",
77
+ "kind": "function_item",
78
+ "status": "removed",
79
+ "before_code": "fn get_access_token_key<F, Req, Res>(\n &self,\n router_data: &hyperswitch_domain_models::router_data::RouterData<F, Req, Res>,\n merchant_connector_id_or_connector_name: String,\n ) -> CustomResult<String, errors::ConnectorError> {\n Ok(format!(\n \"access_token_{}_{}\",\n router_data.merchant_id.get_string_repr(),\n merchant_connector_id_or_connector_name\n ))\n }",
80
+ "after_code": null,
81
+ "diff_span": null,
82
+ "commit_sha": "f69bde896cf380160b893224bf2e6451c4360690"
83
+ }
84
+ ]
85
+ }
diffs/pr_10158/0227ec9/diff.json ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs",
6
+ "crates/external_services/src/http_client/metrics.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/external_services/src/http_client/client.rs::function::get_client_builder",
11
+ "file": "crates/external_services/src/http_client/client.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": false,
15
+ "imports_changed": true,
16
+ "before_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
17
+ "after_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
18
+ "diff_span": {
19
+ "before": "",
20
+ "after": ""
21
+ },
22
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189",
23
+ "before_imports": [
24
+ "use router_env::logger;",
25
+ "pub use common_utils::errors::CustomResult;",
26
+ "use std::time::Duration;"
27
+ ],
28
+ "after_imports": [
29
+ "pub use common_utils::errors::CustomResult;",
30
+ "use router_env::{logger, metric_attributes};"
31
+ ]
32
+ },
33
+ {
34
+ "id": "crates/external_services/src/http_client/client.rs::function::create_client",
35
+ "file": "crates/external_services/src/http_client/client.rs",
36
+ "kind": "function_item",
37
+ "status": "modified",
38
+ "code_changed": false,
39
+ "imports_changed": true,
40
+ "before_code": "pub fn create_client(\n proxy_config: &Proxy,\n client_certificate: Option<masking::Secret<String>>,\n client_certificate_key: Option<masking::Secret<String>>,\n ca_certificate: Option<masking::Secret<String>>,\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // Case 1: Mutual TLS with client certificate and key\n if let (Some(encoded_certificate), Some(encoded_certificate_key)) =\n (client_certificate.clone(), client_certificate_key.clone())\n {\n if ca_certificate.is_some() {\n logger::warn!(\"All of client certificate, client key, and CA certificate are provided. CA certificate will be ignored in mutual TLS setup.\");\n }\n\n logger::debug!(\"Creating HTTP client with mutual TLS (client cert + key)\");\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config);\n\n let identity = create_identity_from_certificate_and_key(\n encoded_certificate.clone(),\n encoded_certificate_key,\n )?;\n let certificate_list = create_certificate(encoded_certificate)?;\n let client_builder = certificate_list\n .into_iter()\n .fold(client_builder, |client_builder, certificate| {\n client_builder.add_root_certificate(certificate)\n });\n return client_builder\n .identity(identity)\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with certificate and certificate key\");\n }\n\n // Case 2: Use provided CA certificate for server authentication only (one-way TLS)\n if let Some(ca_pem) = ca_certificate {\n logger::debug!(\"Creating HTTP client with one-way TLS (CA certificate)\");\n let pem = ca_pem.expose().replace(\"\\\\r\\\\n\", \"\\n\"); // Fix escaped newlines\n let cert = reqwest::Certificate::from_pem(pem.as_bytes())\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to parse CA certificate PEM block\")?;\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .add_root_certificate(cert);\n return client_builder\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with CA certificate\");\n }\n\n // Case 3: Default client (no certs)\n logger::debug!(\"Creating default HTTP client (no client or CA certificates)\");\n get_base_client(proxy_config)\n}",
41
+ "after_code": "pub fn create_client(\n proxy_config: &Proxy,\n client_certificate: Option<masking::Secret<String>>,\n client_certificate_key: Option<masking::Secret<String>>,\n ca_certificate: Option<masking::Secret<String>>,\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // Case 1: Mutual TLS with client certificate and key\n if let (Some(encoded_certificate), Some(encoded_certificate_key)) =\n (client_certificate.clone(), client_certificate_key.clone())\n {\n if ca_certificate.is_some() {\n logger::warn!(\"All of client certificate, client key, and CA certificate are provided. CA certificate will be ignored in mutual TLS setup.\");\n }\n\n logger::debug!(\"Creating HTTP client with mutual TLS (client cert + key)\");\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config);\n\n let identity = create_identity_from_certificate_and_key(\n encoded_certificate.clone(),\n encoded_certificate_key,\n )?;\n let certificate_list = create_certificate(encoded_certificate)?;\n let client_builder = certificate_list\n .into_iter()\n .fold(client_builder, |client_builder, certificate| {\n client_builder.add_root_certificate(certificate)\n });\n return client_builder\n .identity(identity)\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with certificate and certificate key\");\n }\n\n // Case 2: Use provided CA certificate for server authentication only (one-way TLS)\n if let Some(ca_pem) = ca_certificate {\n logger::debug!(\"Creating HTTP client with one-way TLS (CA certificate)\");\n let pem = ca_pem.expose().replace(\"\\\\r\\\\n\", \"\\n\"); // Fix escaped newlines\n let cert = reqwest::Certificate::from_pem(pem.as_bytes())\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to parse CA certificate PEM block\")?;\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .add_root_certificate(cert);\n return client_builder\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with CA certificate\");\n }\n\n // Case 3: Default client (no certs)\n logger::debug!(\"Creating default HTTP client (no client or CA certificates)\");\n get_base_client(proxy_config)\n}",
42
+ "diff_span": {
43
+ "before": "",
44
+ "after": ""
45
+ },
46
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189",
47
+ "before_imports": [
48
+ "use router_env::logger;",
49
+ "pub use common_utils::errors::CustomResult;"
50
+ ],
51
+ "after_imports": [
52
+ "pub use common_utils::errors::CustomResult;",
53
+ "use router_env::{logger, metric_attributes};"
54
+ ]
55
+ },
56
+ {
57
+ "id": "crates/external_services/src/http_client/client.rs::function::apply_mitm_certificate",
58
+ "file": "crates/external_services/src/http_client/client.rs",
59
+ "kind": "function_item",
60
+ "status": "modified",
61
+ "code_changed": false,
62
+ "imports_changed": true,
63
+ "before_code": "fn apply_mitm_certificate(\n mut client_builder: reqwest::ClientBuilder,\n proxy_config: &Proxy,\n) -> reqwest::ClientBuilder {\n if let Some(mitm_ca_cert) = &proxy_config.mitm_ca_certificate {\n let pem = mitm_ca_cert.clone().expose().replace(\"\\\\r\\\\n\", \"\\n\");\n match reqwest::Certificate::from_pem(pem.as_bytes()) {\n Ok(cert) => {\n logger::debug!(\"Successfully added MITM CA certificate\");\n client_builder = client_builder.add_root_certificate(cert);\n }\n Err(err) => {\n logger::error!(\n \"Failed to parse MITM CA certificate: {}, continuing without MITM support\",\n err\n );\n }\n }\n }\n client_builder\n}",
64
+ "after_code": "fn apply_mitm_certificate(\n mut client_builder: reqwest::ClientBuilder,\n proxy_config: &Proxy,\n) -> reqwest::ClientBuilder {\n if let Some(mitm_ca_cert) = &proxy_config.mitm_ca_certificate {\n let pem = mitm_ca_cert.clone().expose().replace(\"\\\\r\\\\n\", \"\\n\");\n match reqwest::Certificate::from_pem(pem.as_bytes()) {\n Ok(cert) => {\n logger::debug!(\"Successfully added MITM CA certificate\");\n client_builder = client_builder.add_root_certificate(cert);\n }\n Err(err) => {\n logger::error!(\n \"Failed to parse MITM CA certificate: {}, continuing without MITM support\",\n err\n );\n }\n }\n }\n client_builder\n}",
65
+ "diff_span": {
66
+ "before": "",
67
+ "after": ""
68
+ },
69
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189",
70
+ "before_imports": [
71
+ "use router_env::logger;"
72
+ ],
73
+ "after_imports": [
74
+ "use router_env::{logger, metric_attributes};"
75
+ ]
76
+ },
77
+ {
78
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
79
+ "file": "crates/external_services/src/http_client/client.rs",
80
+ "kind": "function_item",
81
+ "status": "modified",
82
+ "code_changed": true,
83
+ "imports_changed": true,
84
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct base client\")\n })?\n .clone())\n}",
85
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag.clone());\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag.clone());\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}",
86
+ "diff_span": {
87
+ "before": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct base client\")\n })?\n .clone())\n}",
88
+ "after": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag.clone());\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag.clone());\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}"
89
+ },
90
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189",
91
+ "before_imports": [
92
+ "pub use common_utils::errors::CustomResult;"
93
+ ],
94
+ "after_imports": [
95
+ "pub use common_utils::errors::CustomResult;",
96
+ "use super::metrics;",
97
+ "use router_env::{logger, metric_attributes};"
98
+ ]
99
+ },
100
+ {
101
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::has_proxy_config",
102
+ "file": "crates/external_services/src/http_client/client.rs",
103
+ "kind": "function_item",
104
+ "status": "added",
105
+ "before_code": null,
106
+ "after_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }",
107
+ "diff_span": null,
108
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
109
+ },
110
+ {
111
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
112
+ "file": "crates/external_services/src/http_client/client.rs",
113
+ "kind": "function_item",
114
+ "status": "added",
115
+ "before_code": null,
116
+ "after_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }",
117
+ "diff_span": null,
118
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
119
+ },
120
+ {
121
+ "id": "crates/external_services/src/http_client/client.rs::function::extract_proxy_host",
122
+ "file": "crates/external_services/src/http_client/client.rs",
123
+ "kind": "function_item",
124
+ "status": "added",
125
+ "before_code": null,
126
+ "after_code": "fn extract_proxy_host(url_opt: &Option<String>) -> String {\n url_opt.as_ref()\n .and_then(|url| url::Url::parse(url).ok())\n .and_then(|parsed_url| parsed_url.host_str().map(|s| s.to_string()))\n .unwrap_or_else(|| \"none\".to_string())\n}",
127
+ "diff_span": null,
128
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
129
+ },
130
+ {
131
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
132
+ "file": "crates/external_services/src/http_client/client.rs",
133
+ "kind": "impl_item",
134
+ "status": "added",
135
+ "before_code": null,
136
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
137
+ "diff_span": null,
138
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
139
+ },
140
+ {
141
+ "id": "crates/external_services/src/http_client/client.rs::static::PROXY_CLIENT_CACHE",
142
+ "file": "crates/external_services/src/http_client/client.rs",
143
+ "kind": "static_item",
144
+ "status": "added",
145
+ "before_code": null,
146
+ "after_code": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<String, reqwest::Client>>> = OnceCell::new();",
147
+ "diff_span": null,
148
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
149
+ },
150
+ {
151
+ "id": "crates/external_services/src/http_client/client.rs::trait::ProxyClientCacheKey",
152
+ "file": "crates/external_services/src/http_client/client.rs",
153
+ "kind": "trait_item",
154
+ "status": "added",
155
+ "before_code": null,
156
+ "after_code": "trait ProxyClientCacheKey {\n fn cache_key(&self) -> Option<String>;\n fn has_proxy_config(&self) -> bool;\n}",
157
+ "diff_span": null,
158
+ "commit_sha": "0227ec9fd783b51703a8540cdba5d93e5116b189"
159
+ }
160
+ ]
161
+ }
diffs/pr_10158/0c2988e/diff.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "0c2988e33c70ab79c7366a454044e85eb67aebeb",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": " let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n\n Ok(client)",
19
+ "after": " let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n\n Ok(client)"
20
+ },
21
+ "commit_sha": "0c2988e33c70ab79c7366a454044e85eb67aebeb"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::function::get_or_create_proxy_client",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "function_item",
27
+ "status": "added",
28
+ "before_code": null,
29
+ "after_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // First try read lock - fastest path for cache hits\n if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n }\n\n // Cache miss - need to create new client with write lock\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n \n Ok(new_client)\n}",
30
+ "diff_span": null,
31
+ "commit_sha": "0c2988e33c70ab79c7366a454044e85eb67aebeb"
32
+ },
33
+ {
34
+ "id": "crates/external_services/src/http_client/client.rs::function::create_new_proxy_client",
35
+ "file": "crates/external_services/src/http_client/client.rs",
36
+ "kind": "function_item",
37
+ "status": "removed",
38
+ "before_code": "fn create_new_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n Ok(new_client)\n }\n}",
39
+ "after_code": null,
40
+ "diff_span": null,
41
+ "commit_sha": "0c2988e33c70ab79c7366a454044e85eb67aebeb"
42
+ }
43
+ ]
44
+ }
diffs/pr_10158/152e71c/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "152e71caee0a59c3c7df5592be0384891c4b00d3",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": " .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {",
19
+ "after": " .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {"
20
+ },
21
+ "commit_sha": "152e71caee0a59c3c7df5592be0384891c4b00d3"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/1aaa136/diff.json ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/api_models/src/webhooks.rs",
6
+ "crates/common_enums/src/enums.rs",
7
+ "crates/hyperswitch_connectors/src/connectors/adyenplatform.rs",
8
+ "crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs",
9
+ "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
10
+ "crates/hyperswitch_interfaces/src/webhooks.rs",
11
+ "crates/router/src/core/webhooks/incoming.rs"
12
+ ],
13
+ "diffs": [
14
+ {
15
+ "id": "crates/router/src/core/webhooks/incoming.rs::function::process_webhook_business_logic",
16
+ "file": "crates/router/src/core/webhooks/incoming.rs",
17
+ "kind": "function_item",
18
+ "status": "modified",
19
+ "code_changed": true,
20
+ "imports_changed": false,
21
+ "before_code": "async fn process_webhook_business_logic(\n state: &SessionState,\n req_state: ReqState,\n merchant_context: &domain::MerchantContext,\n connector: &ConnectorEnum,\n connector_name: &str,\n event_type: webhooks::IncomingWebhookEvent,\n source_verified_via_ucs: bool,\n webhook_transform_data: &Option<Box<unified_connector_service::WebhookTransformData>>,\n shadow_ucs_data: &mut Option<ShadowUcsData<'_>>,\n request_details: &IncomingWebhookRequestDetails<'_>,\n is_relay_webhook: bool,\n) -> errors::RouterResult<WebhookResponseTracker> {\n let object_ref_id = connector\n .get_webhook_object_reference_id(request_details)\n .switch()\n .attach_printable(\"Could not find object reference id in incoming webhook body\")?;\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::InvalidDataValue {\n field_name: \"connector\",\n })\n .attach_printable_lazy(|| format!(\"unable to parse connector name {connector_name:?}\"))?;\n let connectors_with_source_verification_call = &state.conf.webhook_source_verification_call;\n\n let merchant_connector_account = match Box::pin(helper_utils::get_mca_from_object_reference_id(\n state,\n object_ref_id.clone(),\n merchant_context,\n connector_name,\n ))\n .await\n {\n Ok(mca) => mca,\n Err(error) => {\n let result = handle_incoming_webhook_error(\n error,\n connector,\n connector_name,\n request_details,\n merchant_context.get_merchant_account().get_id(),\n );\n match result {\n Ok((_, webhook_tracker, _)) => return Ok(webhook_tracker),\n Err(e) => return Err(e),\n }\n }\n };\n\n let source_verified = if source_verified_via_ucs {\n // If UCS handled verification, use that result\n source_verified_via_ucs\n } else {\n // Fall back to traditional source verification\n if connectors_with_source_verification_call\n .connectors_with_webhook_source_verification_call\n .contains(&connector_enum)\n {\n verify_webhook_source_verification_call(\n connector.clone(),\n state,\n merchant_context,\n merchant_connector_account.clone(),\n connector_name,\n request_details,\n )\n .await\n .or_else(|error| match error.current_context() {\n errors::ConnectorError::WebhookSourceVerificationFailed => {\n logger::error!(?error, \"Source Verification Failed\");\n Ok(false)\n }\n _ => Err(error),\n })\n .switch()\n .attach_printable(\"There was an issue in incoming webhook source verification\")?\n } else {\n connector\n .clone()\n .verify_webhook_source(\n request_details,\n merchant_context.get_merchant_account().get_id(),\n merchant_connector_account.connector_webhook_details.clone(),\n merchant_connector_account.connector_account_details.clone(),\n connector_name,\n )\n .await\n .or_else(|error| match error.current_context() {\n errors::ConnectorError::WebhookSourceVerificationFailed => {\n logger::error!(?error, \"Source Verification Failed\");\n Ok(false)\n }\n _ => Err(error),\n })\n .switch()\n .attach_printable(\"There was an issue in incoming webhook source verification\")?\n }\n };\n\n if source_verified {\n metrics::WEBHOOK_SOURCE_VERIFIED_COUNT.add(\n 1,\n router_env::metric_attributes!((\n MERCHANT_ID,\n merchant_context.get_merchant_account().get_id().clone()\n )),\n );\n } else if connector.is_webhook_source_verification_mandatory() {\n // if webhook consumption is mandatory for connector, fail webhook\n // so that merchant can retrigger it after updating merchant_secret\n return Err(errors::ApiErrorResponse::WebhookAuthenticationFailed.into());\n }\n\n logger::info!(source_verified=?source_verified);\n\n let event_object: Box<dyn masking::ErasedMaskSerialize> = match webhook_transform_data {\n Some(webhook_transform_data) => {\n // Extract resource_object from UCS webhook content\n webhook_transform_data\n .webhook_content\n .as_ref()\n .map(|webhook_response_content| {\n get_ucs_webhook_resource_object(webhook_response_content)\n })\n .unwrap_or_else(|| {\n // Fall back to connector extraction\n connector\n .get_webhook_resource_object(request_details)\n .switch()\n .attach_printable(\"Could not find resource object in incoming webhook body\")\n })?\n }\n None => {\n // Use traditional connector extraction\n connector\n .get_webhook_resource_object(request_details)\n .switch()\n .attach_printable(\"Could not find resource object in incoming webhook body\")?\n }\n };\n\n let webhook_details = api::IncomingWebhookDetails {\n object_reference_id: object_ref_id.clone(),\n resource_object: serde_json::to_vec(&event_object)\n .change_context(errors::ParsingError::EncodeError(\"byte-vec\"))\n .attach_printable(\"Unable to convert webhook payload to a value\")\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\n \"There was an issue when encoding the incoming webhook body to bytes\",\n )?,\n };\n\n // Create shadow_event_object and shadow_webhook_details using shadow UCS data\n let shadow_event_object: Option<Box<dyn masking::ErasedMaskSerialize>> =\n shadow_ucs_data.as_ref().and_then(|shadow_data| {\n // Create shadow event object using UCS transform data and shadow request details\n let shadow_event_result = shadow_data\n .ucs_transform_data\n .webhook_content\n .as_ref()\n .map(|webhook_response_content| {\n get_ucs_webhook_resource_object(webhook_response_content)\n })\n .unwrap_or_else(|| {\n // Fall back to connector extraction using shadow request details\n connector\n .get_webhook_resource_object(shadow_data.request_details)\n .switch()\n .attach_printable(\n \"Could not find resource object in shadow incoming webhook body\",\n )\n });\n\n match shadow_event_result {\n Ok(shadow_obj) => Some(shadow_obj),\n Err(error) => {\n logger::warn!(\n connector = connector_name,\n merchant_id = ?merchant_context.get_merchant_account().get_id(),\n error = ?error,\n \"Failed to create shadow event object from UCS transform data\"\n );\n None\n }\n }\n });\n\n let shadow_webhook_details: Option<api::IncomingWebhookDetails> =\n shadow_event_object.as_ref().and_then(|shadow_obj| {\n let resource_object_result = serde_json::to_vec(shadow_obj)\n .change_context(errors::ParsingError::EncodeError(\"byte-vec\"))\n .attach_printable(\"Unable to convert shadow webhook payload to a value\")\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\n \"There was an issue when encoding the shadow incoming webhook body to bytes\",\n );\n\n match resource_object_result {\n Ok(resource_object) => Some(api::IncomingWebhookDetails {\n object_reference_id: object_ref_id.clone(),\n resource_object,\n }),\n Err(error) => {\n logger::warn!(\n connector = connector_name,\n merchant_id = ?merchant_context.get_merchant_account().get_id(),\n error = ?error,\n \"Failed to serialize shadow webhook payload to bytes\"\n );\n None\n }\n }\n });\n\n // Assign shadow_webhook_details to shadow_ucs_data\n if let Some(shadow_data) = shadow_ucs_data.as_mut() {\n shadow_data.webhook_details = shadow_webhook_details;\n }\n\n let profile_id = &merchant_connector_account.profile_id;\n let key_manager_state = &(state).into();\n\n let business_profile = state\n .store\n .find_business_profile_by_profile_id(\n key_manager_state,\n merchant_context.get_merchant_key_store(),\n profile_id,\n )\n .await\n .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {\n id: profile_id.get_string_repr().to_owned(),\n })?;\n\n // If the incoming webhook is a relay webhook, then we need to trigger the relay webhook flow\n let result_response = if is_relay_webhook {\n let relay_webhook_response = Box::pin(relay_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n event_type,\n source_verified,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for relay failed\");\n\n // Using early return ensures unsupported webhooks are acknowledged to the connector\n if let Some(errors::ApiErrorResponse::NotSupported { .. }) = relay_webhook_response\n .as_ref()\n .err()\n .map(|a| a.current_context())\n {\n logger::error!(\n webhook_payload =? request_details.body,\n \"Failed while identifying the event type\",\n );\n\n let _response = connector\n .get_webhook_api_response(request_details, None)\n .switch()\n .attach_printable(\n \"Failed while early return in case of not supported event type in relay webhooks\",\n )?;\n\n return Ok(WebhookResponseTracker::NoEffect);\n };\n\n relay_webhook_response\n } else {\n let flow_type: api::WebhookFlow = event_type.into();\n match flow_type {\n api::WebhookFlow::Payment => Box::pin(payments_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n webhook_transform_data,\n shadow_ucs_data,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for payments failed\"),\n\n api::WebhookFlow::Refund => Box::pin(refunds_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n connector_name,\n source_verified,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for refunds failed\"),\n\n api::WebhookFlow::Dispute => Box::pin(disputes_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for disputes failed\"),\n\n api::WebhookFlow::BankTransfer => Box::pin(bank_transfer_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n ))\n .await\n .attach_printable(\"Incoming bank-transfer webhook flow failed\"),\n\n api::WebhookFlow::ReturnResponse => Ok(WebhookResponseTracker::NoEffect),\n\n api::WebhookFlow::Mandate => Box::pin(mandates_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for mandates failed\"),\n\n api::WebhookFlow::ExternalAuthentication => {\n Box::pin(external_authentication_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n source_verified,\n event_type,\n request_details,\n connector,\n object_ref_id,\n business_profile,\n merchant_connector_account,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for external authentication failed\")\n }\n api::WebhookFlow::FraudCheck => Box::pin(frm_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n source_verified,\n event_type,\n object_ref_id,\n business_profile,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for fraud check failed\"),\n\n #[cfg(feature = \"payouts\")]\n api::WebhookFlow::Payout => Box::pin(payouts_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n event_type,\n source_verified,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for payouts failed\"),\n\n api::WebhookFlow::Subscription => {\n Box::pin(subscriptions::webhooks::incoming_webhook_flow(\n state.clone().into(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n merchant_connector_account,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for subscription failed\")\n }\n\n _ => Err(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"Unsupported Flow Type received in incoming webhooks\"),\n }\n };\n\n match result_response {\n Ok(response) => Ok(response),\n Err(error) => {\n let result = handle_incoming_webhook_error(\n error,\n connector,\n connector_name,\n request_details,\n merchant_context.get_merchant_account().get_id(),\n );\n match result {\n Ok((_, webhook_tracker, _)) => Ok(webhook_tracker),\n Err(e) => Err(e),\n }\n }\n }\n}",
22
+ "after_code": "async fn process_webhook_business_logic(\n state: &SessionState,\n req_state: ReqState,\n merchant_context: &domain::MerchantContext,\n connector: &ConnectorEnum,\n connector_name: &str,\n event_type: webhooks::IncomingWebhookEvent,\n source_verified_via_ucs: bool,\n webhook_transform_data: &Option<Box<unified_connector_service::WebhookTransformData>>,\n shadow_ucs_data: &mut Option<ShadowUcsData<'_>>,\n request_details: &IncomingWebhookRequestDetails<'_>,\n is_relay_webhook: bool,\n) -> errors::RouterResult<WebhookResponseTracker> {\n let object_ref_id = connector\n .get_webhook_object_reference_id(request_details)\n .switch()\n .attach_printable(\"Could not find object reference id in incoming webhook body\")?;\n let connector_enum = Connector::from_str(connector_name)\n .change_context(errors::ApiErrorResponse::InvalidDataValue {\n field_name: \"connector\",\n })\n .attach_printable_lazy(|| format!(\"unable to parse connector name {connector_name:?}\"))?;\n let connectors_with_source_verification_call = &state.conf.webhook_source_verification_call;\n\n let merchant_connector_account = match Box::pin(helper_utils::get_mca_from_object_reference_id(\n state,\n object_ref_id.clone(),\n merchant_context,\n connector_name,\n ))\n .await\n {\n Ok(mca) => mca,\n Err(error) => {\n let result = handle_incoming_webhook_error(\n error,\n connector,\n connector_name,\n request_details,\n merchant_context.get_merchant_account().get_id(),\n );\n match result {\n Ok((_, webhook_tracker, _)) => return Ok(webhook_tracker),\n Err(e) => return Err(e),\n }\n }\n };\n\n let source_verified = if source_verified_via_ucs {\n // If UCS handled verification, use that result\n source_verified_via_ucs\n } else {\n // Fall back to traditional source verification\n if connectors_with_source_verification_call\n .connectors_with_webhook_source_verification_call\n .contains(&connector_enum)\n {\n verify_webhook_source_verification_call(\n connector.clone(),\n state,\n merchant_context,\n merchant_connector_account.clone(),\n connector_name,\n request_details,\n )\n .await\n .or_else(|error| match error.current_context() {\n errors::ConnectorError::WebhookSourceVerificationFailed => {\n logger::error!(?error, \"Source Verification Failed\");\n Ok(false)\n }\n _ => Err(error),\n })\n .switch()\n .attach_printable(\"There was an issue in incoming webhook source verification\")?\n } else {\n connector\n .clone()\n .verify_webhook_source(\n request_details,\n merchant_context.get_merchant_account().get_id(),\n merchant_connector_account.connector_webhook_details.clone(),\n merchant_connector_account.connector_account_details.clone(),\n connector_name,\n )\n .await\n .or_else(|error| match error.current_context() {\n errors::ConnectorError::WebhookSourceVerificationFailed => {\n logger::error!(?error, \"Source Verification Failed\");\n Ok(false)\n }\n _ => Err(error),\n })\n .switch()\n .attach_printable(\"There was an issue in incoming webhook source verification\")?\n }\n };\n\n if source_verified {\n metrics::WEBHOOK_SOURCE_VERIFIED_COUNT.add(\n 1,\n router_env::metric_attributes!((\n MERCHANT_ID,\n merchant_context.get_merchant_account().get_id().clone()\n )),\n );\n } else if connector.is_webhook_source_verification_mandatory() {\n // if webhook consumption is mandatory for connector, fail webhook\n // so that merchant can retrigger it after updating merchant_secret\n return Err(errors::ApiErrorResponse::WebhookAuthenticationFailed.into());\n }\n\n logger::info!(source_verified=?source_verified);\n\n let event_object: Box<dyn masking::ErasedMaskSerialize> = match webhook_transform_data {\n Some(webhook_transform_data) => {\n // Extract resource_object from UCS webhook content\n webhook_transform_data\n .webhook_content\n .as_ref()\n .map(|webhook_response_content| {\n get_ucs_webhook_resource_object(webhook_response_content)\n })\n .unwrap_or_else(|| {\n // Fall back to connector extraction\n connector\n .get_webhook_resource_object(request_details)\n .switch()\n .attach_printable(\"Could not find resource object in incoming webhook body\")\n })?\n }\n None => {\n // Use traditional connector extraction\n connector\n .get_webhook_resource_object(request_details)\n .switch()\n .attach_printable(\"Could not find resource object in incoming webhook body\")?\n }\n };\n\n let webhook_details = api::IncomingWebhookDetails {\n object_reference_id: object_ref_id.clone(),\n resource_object: serde_json::to_vec(&event_object)\n .change_context(errors::ParsingError::EncodeError(\"byte-vec\"))\n .attach_printable(\"Unable to convert webhook payload to a value\")\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\n \"There was an issue when encoding the incoming webhook body to bytes\",\n )?,\n };\n\n // Create shadow_event_object and shadow_webhook_details using shadow UCS data\n let shadow_event_object: Option<Box<dyn masking::ErasedMaskSerialize>> =\n shadow_ucs_data.as_ref().and_then(|shadow_data| {\n // Create shadow event object using UCS transform data and shadow request details\n let shadow_event_result = shadow_data\n .ucs_transform_data\n .webhook_content\n .as_ref()\n .map(|webhook_response_content| {\n get_ucs_webhook_resource_object(webhook_response_content)\n })\n .unwrap_or_else(|| {\n // Fall back to connector extraction using shadow request details\n connector\n .get_webhook_resource_object(shadow_data.request_details)\n .switch()\n .attach_printable(\n \"Could not find resource object in shadow incoming webhook body\",\n )\n });\n\n match shadow_event_result {\n Ok(shadow_obj) => Some(shadow_obj),\n Err(error) => {\n logger::warn!(\n connector = connector_name,\n merchant_id = ?merchant_context.get_merchant_account().get_id(),\n error = ?error,\n \"Failed to create shadow event object from UCS transform data\"\n );\n None\n }\n }\n });\n\n let shadow_webhook_details: Option<api::IncomingWebhookDetails> =\n shadow_event_object.as_ref().and_then(|shadow_obj| {\n let resource_object_result = serde_json::to_vec(shadow_obj)\n .change_context(errors::ParsingError::EncodeError(\"byte-vec\"))\n .attach_printable(\"Unable to convert shadow webhook payload to a value\")\n .change_context(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\n \"There was an issue when encoding the shadow incoming webhook body to bytes\",\n );\n\n match resource_object_result {\n Ok(resource_object) => Some(api::IncomingWebhookDetails {\n object_reference_id: object_ref_id.clone(),\n resource_object,\n }),\n Err(error) => {\n logger::warn!(\n connector = connector_name,\n merchant_id = ?merchant_context.get_merchant_account().get_id(),\n error = ?error,\n \"Failed to serialize shadow webhook payload to bytes\"\n );\n None\n }\n }\n });\n\n // Assign shadow_webhook_details to shadow_ucs_data\n if let Some(shadow_data) = shadow_ucs_data.as_mut() {\n shadow_data.webhook_details = shadow_webhook_details;\n }\n\n let profile_id = &merchant_connector_account.profile_id;\n let key_manager_state = &(state).into();\n\n let business_profile = state\n .store\n .find_business_profile_by_profile_id(\n key_manager_state,\n merchant_context.get_merchant_key_store(),\n profile_id,\n )\n .await\n .to_not_found_response(errors::ApiErrorResponse::ProfileNotFound {\n id: profile_id.get_string_repr().to_owned(),\n })?;\n\n // If the incoming webhook is a relay webhook, then we need to trigger the relay webhook flow\n let result_response = if is_relay_webhook {\n let relay_webhook_response = Box::pin(relay_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n event_type,\n source_verified,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for relay failed\");\n\n // Using early return ensures unsupported webhooks are acknowledged to the connector\n if let Some(errors::ApiErrorResponse::NotSupported { .. }) = relay_webhook_response\n .as_ref()\n .err()\n .map(|a| a.current_context())\n {\n logger::error!(\n webhook_payload =? request_details.body,\n \"Failed while identifying the event type\",\n );\n\n let _response = connector\n .get_webhook_api_response(request_details, None)\n .switch()\n .attach_printable(\n \"Failed while early return in case of not supported event type in relay webhooks\",\n )?;\n\n return Ok(WebhookResponseTracker::NoEffect);\n };\n\n relay_webhook_response\n } else {\n let flow_type: api::WebhookFlow = event_type.into();\n match flow_type {\n api::WebhookFlow::Payment => Box::pin(payments_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n webhook_transform_data,\n shadow_ucs_data,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for payments failed\"),\n\n api::WebhookFlow::Refund => Box::pin(refunds_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n connector_name,\n source_verified,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for refunds failed\"),\n\n api::WebhookFlow::Dispute => Box::pin(disputes_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for disputes failed\"),\n\n api::WebhookFlow::BankTransfer => Box::pin(bank_transfer_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n ))\n .await\n .attach_printable(\"Incoming bank-transfer webhook flow failed\"),\n\n api::WebhookFlow::ReturnResponse => Ok(WebhookResponseTracker::NoEffect),\n\n api::WebhookFlow::Mandate => Box::pin(mandates_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n event_type,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for mandates failed\"),\n\n api::WebhookFlow::ExternalAuthentication => {\n Box::pin(external_authentication_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n source_verified,\n event_type,\n request_details,\n connector,\n object_ref_id,\n business_profile,\n merchant_connector_account,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for external authentication failed\")\n }\n api::WebhookFlow::FraudCheck => Box::pin(frm_incoming_webhook_flow(\n state.clone(),\n req_state,\n merchant_context.clone(),\n source_verified,\n event_type,\n object_ref_id,\n business_profile,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for fraud check failed\"),\n\n #[cfg(feature = \"payouts\")]\n api::WebhookFlow::Payout => Box::pin(payouts_incoming_webhook_flow(\n state.clone(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n event_type,\n source_verified,\n request_details,\n connector,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for payouts failed\"),\n\n api::WebhookFlow::Subscription => {\n Box::pin(subscriptions::webhooks::incoming_webhook_flow(\n state.clone().into(),\n merchant_context.clone(),\n business_profile,\n webhook_details,\n source_verified,\n connector,\n request_details,\n event_type,\n merchant_connector_account,\n ))\n .await\n .attach_printable(\"Incoming webhook flow for subscription failed\")\n }\n\n _ => Err(errors::ApiErrorResponse::InternalServerError)\n .attach_printable(\"Unsupported Flow Type received in incoming webhooks\"),\n }\n };\n\n match result_response {\n Ok(response) => Ok(response),\n Err(error) => {\n let result = handle_incoming_webhook_error(\n error,\n connector,\n connector_name,\n request_details,\n merchant_context.get_merchant_account().get_id(),\n );\n match result {\n Ok((_, webhook_tracker, _)) => Ok(webhook_tracker),\n Err(e) => Err(e),\n }\n }\n }\n}",
23
+ "diff_span": {
24
+ "before": "",
25
+ "after": " event_type,\n source_verified,\n request_details,\n connector,\n ))\n .await"
26
+ },
27
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
28
+ },
29
+ {
30
+ "id": "crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs::struct::AdyenplatformTrackingData",
31
+ "file": "crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs",
32
+ "kind": "struct_item",
33
+ "status": "modified",
34
+ "code_changed": true,
35
+ "imports_changed": false,
36
+ "before_code": "pub struct AdyenplatformTrackingData {\n status: TrackingStatus,\n estimated_arrival_time: Option<String>,\n}",
37
+ "after_code": "pub struct AdyenplatformTrackingData {\n pub status: TrackingStatus,\n pub reason: Option<String>,\n pub estimated_arrival_time: Option<String>,\n}",
38
+ "diff_span": {
39
+ "before": "pub struct AdyenplatformTrackingData {\n status: TrackingStatus,\n estimated_arrival_time: Option<String>,\n}",
40
+ "after": "pub struct AdyenplatformTrackingData {\n pub status: TrackingStatus,\n pub reason: Option<String>,\n pub estimated_arrival_time: Option<String>,\n}"
41
+ },
42
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
43
+ },
44
+ {
45
+ "id": "crates/hyperswitch_interfaces/src/webhooks.rs::trait::IncomingWebhook",
46
+ "file": "crates/hyperswitch_interfaces/src/webhooks.rs",
47
+ "kind": "trait_item",
48
+ "status": "modified",
49
+ "code_changed": true,
50
+ "imports_changed": false,
51
+ "before_code": "pub trait IncomingWebhook: ConnectorCommon + Sync {\n /// fn get_webhook_body_decoding_algorithm\n fn get_webhook_body_decoding_algorithm(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn crypto::DecodeMessage + Send>, errors::ConnectorError> {\n Ok(Box::new(crypto::NoAlgorithm))\n }\n\n /// fn get_webhook_body_decoding_message\n fn get_webhook_body_decoding_message(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(request.body.to_vec())\n }\n\n /// fn decode_webhook_body\n async fn decode_webhook_body(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n connector_name: &str,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let algorithm = self.get_webhook_body_decoding_algorithm(request)?;\n\n let message = self\n .get_webhook_body_decoding_message(request)\n .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;\n let secret = self\n .get_webhook_source_verification_merchant_secret(\n merchant_id,\n connector_name,\n connector_webhook_details,\n )\n .await\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n algorithm\n .decode_message(&secret.secret, message.into())\n .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)\n }\n\n /// fn get_webhook_source_verification_algorithm\n fn get_webhook_source_verification_algorithm(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn crypto::VerifySignature + Send>, errors::ConnectorError> {\n Ok(Box::new(crypto::NoAlgorithm))\n }\n\n /// fn get_webhook_source_verification_merchant_secret\n async fn get_webhook_source_verification_merchant_secret(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_name: &str,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<api_models::webhooks::ConnectorWebhookSecrets, errors::ConnectorError> {\n let debug_suffix =\n format!(\"For merchant_id: {merchant_id:?}, and connector_name: {connector_name}\");\n let default_secret = \"default_secret\".to_string();\n let merchant_secret = match connector_webhook_details {\n Some(merchant_connector_webhook_details) => {\n let connector_webhook_details = merchant_connector_webhook_details\n .parse_value::<api_models::admin::MerchantConnectorWebhookDetails>(\n \"MerchantConnectorWebhookDetails\",\n )\n .change_context_lazy(|| errors::ConnectorError::WebhookSourceVerificationFailed)\n .attach_printable_lazy(|| {\n format!(\n \"Deserializing MerchantConnectorWebhookDetails failed {debug_suffix}\",\n )\n })?;\n api_models::webhooks::ConnectorWebhookSecrets {\n secret: connector_webhook_details\n .merchant_secret\n .expose()\n .into_bytes(),\n additional_secret: connector_webhook_details.additional_secret,\n }\n }\n\n None => api_models::webhooks::ConnectorWebhookSecrets {\n secret: default_secret.into_bytes(),\n additional_secret: None,\n },\n };\n\n //need to fetch merchant secret from config table with caching in future for enhanced performance\n\n //If merchant has not set the secret for webhook source verification, \"default_secret\" is returned.\n //So it will fail during verification step and goes to psync flow.\n Ok(merchant_secret)\n }\n\n /// fn get_webhook_source_verification_signature\n fn get_webhook_source_verification_signature(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(Vec::new())\n }\n\n /// fn get_webhook_source_verification_message\n fn get_webhook_source_verification_message(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _merchant_id: &common_utils::id_type::MerchantId,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(Vec::new())\n }\n\n /// fn verify_webhook_source\n async fn verify_webhook_source(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n _connector_account_details: crypto::Encryptable<Secret<serde_json::Value>>,\n connector_name: &str,\n ) -> CustomResult<bool, errors::ConnectorError> {\n let algorithm = self\n .get_webhook_source_verification_algorithm(request)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let connector_webhook_secrets = self\n .get_webhook_source_verification_merchant_secret(\n merchant_id,\n connector_name,\n connector_webhook_details,\n )\n .await\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let signature = self\n .get_webhook_source_verification_signature(request, &connector_webhook_secrets)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let message = self\n .get_webhook_source_verification_message(\n request,\n merchant_id,\n &connector_webhook_secrets,\n )\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n algorithm\n .verify_signature(&connector_webhook_secrets.secret, &signature, &message)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)\n }\n\n /// fn get_webhook_object_reference_id\n fn get_webhook_object_reference_id(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError>;\n\n /// fn get_webhook_event_type\n fn get_webhook_event_type(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError>;\n\n /// fn get_webhook_resource_object\n fn get_webhook_resource_object(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError>;\n\n /// fn get_webhook_api_response\n fn get_webhook_api_response(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _error_kind: Option<IncomingWebhookFlowError>,\n ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {\n Ok(ApplicationResponse::StatusOk)\n }\n\n /// fn get_dispute_details\n fn get_dispute_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<crate::disputes::DisputePayload, errors::ConnectorError> {\n Err(errors::ConnectorError::NotImplemented(\"get_dispute_details method\".to_string()).into())\n }\n\n /// fn get_external_authentication_details\n fn get_external_authentication_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<crate::authentication::ExternalAuthenticationPayload, errors::ConnectorError>\n {\n Err(errors::ConnectorError::NotImplemented(\n \"get_external_authentication_details method\".to_string(),\n )\n .into())\n }\n\n /// fn get_mandate_details\n fn get_mandate_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n Option<hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails>,\n errors::ConnectorError,\n > {\n Ok(None)\n }\n\n /// fn get_network_txn_id\n fn get_network_txn_id(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n Option<hyperswitch_domain_models::router_flow_types::ConnectorNetworkTxnId>,\n errors::ConnectorError,\n > {\n Ok(None)\n }\n\n #[cfg(all(feature = \"revenue_recovery\", feature = \"v2\"))]\n /// get revenue recovery invoice details\n fn get_revenue_recovery_attempt_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::revenue_recovery::RevenueRecoveryAttemptData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_revenue_recovery_attempt_details method\".to_string(),\n )\n .into())\n }\n #[cfg(all(feature = \"revenue_recovery\", feature = \"v2\"))]\n /// get revenue recovery transaction details\n fn get_revenue_recovery_invoice_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::revenue_recovery::RevenueRecoveryInvoiceData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_revenue_recovery_invoice_details method\".to_string(),\n )\n .into())\n }\n\n /// get subscription MIT payment data from webhook\n fn get_subscription_mit_payment_data(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::router_flow_types::SubscriptionMitPaymentData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_subscription_mit_payment_data method\".to_string(),\n )\n .into())\n }\n}",
52
+ "after_code": "pub trait IncomingWebhook: ConnectorCommon + Sync {\n /// fn get_webhook_body_decoding_algorithm\n fn get_webhook_body_decoding_algorithm(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn crypto::DecodeMessage + Send>, errors::ConnectorError> {\n Ok(Box::new(crypto::NoAlgorithm))\n }\n\n /// fn get_webhook_body_decoding_message\n fn get_webhook_body_decoding_message(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(request.body.to_vec())\n }\n\n /// fn decode_webhook_body\n async fn decode_webhook_body(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n connector_name: &str,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n let algorithm = self.get_webhook_body_decoding_algorithm(request)?;\n\n let message = self\n .get_webhook_body_decoding_message(request)\n .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;\n let secret = self\n .get_webhook_source_verification_merchant_secret(\n merchant_id,\n connector_name,\n connector_webhook_details,\n )\n .await\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n algorithm\n .decode_message(&secret.secret, message.into())\n .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)\n }\n\n /// fn get_webhook_source_verification_algorithm\n fn get_webhook_source_verification_algorithm(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn crypto::VerifySignature + Send>, errors::ConnectorError> {\n Ok(Box::new(crypto::NoAlgorithm))\n }\n\n /// fn get_webhook_source_verification_merchant_secret\n async fn get_webhook_source_verification_merchant_secret(\n &self,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_name: &str,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n ) -> CustomResult<api_models::webhooks::ConnectorWebhookSecrets, errors::ConnectorError> {\n let debug_suffix =\n format!(\"For merchant_id: {merchant_id:?}, and connector_name: {connector_name}\");\n let default_secret = \"default_secret\".to_string();\n let merchant_secret = match connector_webhook_details {\n Some(merchant_connector_webhook_details) => {\n let connector_webhook_details = merchant_connector_webhook_details\n .parse_value::<api_models::admin::MerchantConnectorWebhookDetails>(\n \"MerchantConnectorWebhookDetails\",\n )\n .change_context_lazy(|| errors::ConnectorError::WebhookSourceVerificationFailed)\n .attach_printable_lazy(|| {\n format!(\n \"Deserializing MerchantConnectorWebhookDetails failed {debug_suffix}\",\n )\n })?;\n api_models::webhooks::ConnectorWebhookSecrets {\n secret: connector_webhook_details\n .merchant_secret\n .expose()\n .into_bytes(),\n additional_secret: connector_webhook_details.additional_secret,\n }\n }\n\n None => api_models::webhooks::ConnectorWebhookSecrets {\n secret: default_secret.into_bytes(),\n additional_secret: None,\n },\n };\n\n //need to fetch merchant secret from config table with caching in future for enhanced performance\n\n //If merchant has not set the secret for webhook source verification, \"default_secret\" is returned.\n //So it will fail during verification step and goes to psync flow.\n Ok(merchant_secret)\n }\n\n /// fn get_webhook_source_verification_signature\n fn get_webhook_source_verification_signature(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(Vec::new())\n }\n\n /// fn get_webhook_source_verification_message\n fn get_webhook_source_verification_message(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _merchant_id: &common_utils::id_type::MerchantId,\n _connector_webhook_secrets: &api_models::webhooks::ConnectorWebhookSecrets,\n ) -> CustomResult<Vec<u8>, errors::ConnectorError> {\n Ok(Vec::new())\n }\n\n /// fn verify_webhook_source\n async fn verify_webhook_source(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n merchant_id: &common_utils::id_type::MerchantId,\n connector_webhook_details: Option<common_utils::pii::SecretSerdeValue>,\n _connector_account_details: crypto::Encryptable<Secret<serde_json::Value>>,\n connector_name: &str,\n ) -> CustomResult<bool, errors::ConnectorError> {\n let algorithm = self\n .get_webhook_source_verification_algorithm(request)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let connector_webhook_secrets = self\n .get_webhook_source_verification_merchant_secret(\n merchant_id,\n connector_name,\n connector_webhook_details,\n )\n .await\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let signature = self\n .get_webhook_source_verification_signature(request, &connector_webhook_secrets)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n let message = self\n .get_webhook_source_verification_message(\n request,\n merchant_id,\n &connector_webhook_secrets,\n )\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;\n\n algorithm\n .verify_signature(&connector_webhook_secrets.secret, &signature, &message)\n .change_context(errors::ConnectorError::WebhookSourceVerificationFailed)\n }\n\n /// fn get_webhook_object_reference_id\n fn get_webhook_object_reference_id(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError>;\n\n /// fn get_status_update_object\n #[cfg(feature = \"payouts\")]\n fn get_payout_webhook_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::PayoutWebhookUpdate, errors::ConnectorError> {\n Ok(api_models::webhooks::PayoutWebhookUpdate {\n error_code: None,\n error_message: None,\n })\n }\n\n /// fn get_webhook_event_type\n fn get_webhook_event_type(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError>;\n\n /// fn get_webhook_resource_object\n fn get_webhook_resource_object(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError>;\n\n /// fn get_webhook_api_response\n fn get_webhook_api_response(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n _error_kind: Option<IncomingWebhookFlowError>,\n ) -> CustomResult<ApplicationResponse<serde_json::Value>, errors::ConnectorError> {\n Ok(ApplicationResponse::StatusOk)\n }\n\n /// fn get_dispute_details\n fn get_dispute_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<crate::disputes::DisputePayload, errors::ConnectorError> {\n Err(errors::ConnectorError::NotImplemented(\"get_dispute_details method\".to_string()).into())\n }\n\n /// fn get_external_authentication_details\n fn get_external_authentication_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<crate::authentication::ExternalAuthenticationPayload, errors::ConnectorError>\n {\n Err(errors::ConnectorError::NotImplemented(\n \"get_external_authentication_details method\".to_string(),\n )\n .into())\n }\n\n /// fn get_mandate_details\n fn get_mandate_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n Option<hyperswitch_domain_models::router_flow_types::ConnectorMandateDetails>,\n errors::ConnectorError,\n > {\n Ok(None)\n }\n\n /// fn get_network_txn_id\n fn get_network_txn_id(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n Option<hyperswitch_domain_models::router_flow_types::ConnectorNetworkTxnId>,\n errors::ConnectorError,\n > {\n Ok(None)\n }\n\n #[cfg(all(feature = \"revenue_recovery\", feature = \"v2\"))]\n /// get revenue recovery invoice details\n fn get_revenue_recovery_attempt_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::revenue_recovery::RevenueRecoveryAttemptData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_revenue_recovery_attempt_details method\".to_string(),\n )\n .into())\n }\n #[cfg(all(feature = \"revenue_recovery\", feature = \"v2\"))]\n /// get revenue recovery transaction details\n fn get_revenue_recovery_invoice_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::revenue_recovery::RevenueRecoveryInvoiceData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_revenue_recovery_invoice_details method\".to_string(),\n )\n .into())\n }\n\n /// get subscription MIT payment data from webhook\n fn get_subscription_mit_payment_data(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<\n hyperswitch_domain_models::router_flow_types::SubscriptionMitPaymentData,\n errors::ConnectorError,\n > {\n Err(errors::ConnectorError::NotImplemented(\n \"get_subscription_mit_payment_data method\".to_string(),\n )\n .into())\n }\n}",
53
+ "diff_span": {
54
+ "before": "",
55
+ "after": " ) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError>;\n\n /// fn get_status_update_object\n #[cfg(feature = \"payouts\")]\n fn get_payout_webhook_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::PayoutWebhookUpdate, errors::ConnectorError> {\n Ok(api_models::webhooks::PayoutWebhookUpdate {\n error_code: None,\n error_message: None,\n })\n }\n\n /// fn get_webhook_event_type\n fn get_webhook_event_type("
56
+ },
57
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
58
+ },
59
+ {
60
+ "id": "crates/router/src/core/webhooks/incoming.rs::function::payouts_incoming_webhook_flow",
61
+ "file": "crates/router/src/core/webhooks/incoming.rs",
62
+ "kind": "function_item",
63
+ "status": "modified",
64
+ "code_changed": true,
65
+ "imports_changed": true,
66
+ "before_code": "async fn payouts_incoming_webhook_flow(\n state: SessionState,\n merchant_context: domain::MerchantContext,\n business_profile: domain::Profile,\n webhook_details: api::IncomingWebhookDetails,\n event_type: webhooks::IncomingWebhookEvent,\n source_verified: bool,\n) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {\n metrics::INCOMING_PAYOUT_WEBHOOK_METRIC.add(1, &[]);\n if source_verified {\n let db = &*state.store;\n //find payout_attempt by object_reference_id\n let payout_attempt = match webhook_details.object_reference_id {\n webhooks::ObjectReferenceId::PayoutId(payout_id_type) => match payout_id_type {\n webhooks::PayoutIdType::PayoutAttemptId(id) => db\n .find_payout_attempt_by_merchant_id_payout_attempt_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n webhooks::PayoutIdType::ConnectorPayoutId(id) => db\n .find_payout_attempt_by_merchant_id_connector_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n },\n _ => Err(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"received a non-payout id when processing payout webhooks\")?,\n };\n\n let payouts = db\n .find_payout_by_merchant_id_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &payout_attempt.payout_id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout\")?;\n\n let payout_attempt_update = PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status: common_enums::PayoutStatus::foreign_try_from(event_type)\n .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"failed payout status mapping from event type\")?,\n error_message: None,\n error_code: None,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n };\n\n let action_req =\n payout_models::PayoutRequest::PayoutActionRequest(payout_models::PayoutActionRequest {\n payout_id: payouts.payout_id.clone(),\n });\n\n let mut payout_data = Box::pin(payouts::make_payout_data(\n &state,\n &merchant_context,\n None,\n &action_req,\n common_utils::consts::DEFAULT_LOCALE,\n ))\n .await?;\n\n let updated_payout_attempt = db\n .update_payout_attempt(\n &payout_attempt,\n payout_attempt_update,\n &payout_data.payouts,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable_lazy(|| {\n format!(\n \"Failed while updating payout attempt: payout_attempt_id: {}\",\n payout_attempt.payout_attempt_id\n )\n })?;\n payout_data.payout_attempt = updated_payout_attempt;\n\n let event_type: Option<enums::EventType> = payout_data.payout_attempt.status.into();\n\n // If event is NOT an UnsupportedEvent, trigger Outgoing Webhook\n if let Some(outgoing_event_type) = event_type {\n let payout_create_response =\n payouts::response_handler(&state, &merchant_context, &payout_data).await?;\n\n Box::pin(super::create_event_and_trigger_outgoing_webhook(\n state,\n merchant_context,\n business_profile,\n outgoing_event_type,\n enums::EventClass::Payouts,\n payout_data\n .payout_attempt\n .payout_id\n .get_string_repr()\n .to_string(),\n enums::EventObjectType::PayoutDetails,\n api::OutgoingWebhookContent::PayoutDetails(Box::new(payout_create_response)),\n Some(payout_data.payout_attempt.created_at),\n ))\n .await?;\n }\n\n Ok(WebhookResponseTracker::Payout {\n payout_id: payout_data.payout_attempt.payout_id,\n status: payout_data.payout_attempt.status,\n })\n } else {\n metrics::INCOMING_PAYOUT_WEBHOOK_SIGNATURE_FAILURE_METRIC.add(1, &[]);\n Err(report!(\n errors::ApiErrorResponse::WebhookAuthenticationFailed\n ))\n }\n}",
67
+ "after_code": "async fn payouts_incoming_webhook_flow(\n state: SessionState,\n merchant_context: domain::MerchantContext,\n business_profile: domain::Profile,\n webhook_details: api::IncomingWebhookDetails,\n event_type: webhooks::IncomingWebhookEvent,\n source_verified: bool,\n request_details: &IncomingWebhookRequestDetails<'_>,\n connector: &ConnectorEnum,\n) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {\n metrics::INCOMING_PAYOUT_WEBHOOK_METRIC.add(1, &[]);\n if source_verified {\n let db = &*state.store;\n //find payout_attempt by object_reference_id\n let payout_attempt = match webhook_details.object_reference_id {\n webhooks::ObjectReferenceId::PayoutId(payout_id_type) => match payout_id_type {\n webhooks::PayoutIdType::PayoutAttemptId(id) => db\n .find_payout_attempt_by_merchant_id_payout_attempt_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n webhooks::PayoutIdType::ConnectorPayoutId(id) => db\n .find_payout_attempt_by_merchant_id_connector_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n },\n _ => Err(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"received a non-payout id when processing payout webhooks\")?,\n };\n\n let payouts = db\n .find_payout_by_merchant_id_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &payout_attempt.payout_id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout\")?;\n\n let status = common_enums::PayoutStatus::foreign_try_from(event_type)\n .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"failed payout status mapping from event type\")?;\n\n let payout_webhook_details = connector\n .get_payout_webhook_details(request_details)\n .switch()\n .attach_printable(\"Failed to get error object for payouts\")?;\n\n // if status is failure then update the error_code and error_message as well\n let payout_attempt_update = if status.is_payout_failure() {\n PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status,\n error_message: payout_webhook_details.error_message,\n error_code: payout_webhook_details.error_code,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n }\n } else {\n PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status,\n error_message: None,\n error_code: None,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n }\n };\n\n let action_req =\n payout_models::PayoutRequest::PayoutActionRequest(payout_models::PayoutActionRequest {\n payout_id: payouts.payout_id.clone(),\n });\n\n let mut payout_data = Box::pin(payouts::make_payout_data(\n &state,\n &merchant_context,\n None,\n &action_req,\n common_utils::consts::DEFAULT_LOCALE,\n ))\n .await?;\n\n let updated_payout_attempt = db\n .update_payout_attempt(\n &payout_attempt,\n payout_attempt_update,\n &payout_data.payouts,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable_lazy(|| {\n format!(\n \"Failed while updating payout attempt: payout_attempt_id: {}\",\n payout_attempt.payout_attempt_id\n )\n })?;\n payout_data.payout_attempt = updated_payout_attempt;\n\n let event_type: Option<enums::EventType> = payout_data.payout_attempt.status.into();\n\n // If event is NOT an UnsupportedEvent, trigger Outgoing Webhook\n if let Some(outgoing_event_type) = event_type {\n let payout_create_response =\n payouts::response_handler(&state, &merchant_context, &payout_data).await?;\n\n Box::pin(super::create_event_and_trigger_outgoing_webhook(\n state,\n merchant_context,\n business_profile,\n outgoing_event_type,\n enums::EventClass::Payouts,\n payout_data\n .payout_attempt\n .payout_id\n .get_string_repr()\n .to_string(),\n enums::EventObjectType::PayoutDetails,\n api::OutgoingWebhookContent::PayoutDetails(Box::new(payout_create_response)),\n Some(payout_data.payout_attempt.created_at),\n ))\n .await?;\n }\n\n Ok(WebhookResponseTracker::Payout {\n payout_id: payout_data.payout_attempt.payout_id,\n status: payout_data.payout_attempt.status,\n })\n } else {\n metrics::INCOMING_PAYOUT_WEBHOOK_SIGNATURE_FAILURE_METRIC.add(1, &[]);\n Err(report!(\n errors::ApiErrorResponse::WebhookAuthenticationFailed\n ))\n }\n}",
68
+ "diff_span": {
69
+ "before": " .attach_printable(\"Failed to fetch the payout\")?;\n\n let payout_attempt_update = PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status: common_enums::PayoutStatus::foreign_try_from(event_type)\n .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"failed payout status mapping from event type\")?,\n error_message: None,\n error_code: None,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n };\n",
70
+ "after": " event_type: webhooks::IncomingWebhookEvent,\n source_verified: bool,\n request_details: &IncomingWebhookRequestDetails<'_>,\n connector: &ConnectorEnum,\n) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {\n metrics::INCOMING_PAYOUT_WEBHOOK_METRIC.add(1, &[]);\n if source_verified {\n let db = &*state.store;\n //find payout_attempt by object_reference_id\n let payout_attempt = match webhook_details.object_reference_id {\n webhooks::ObjectReferenceId::PayoutId(payout_id_type) => match payout_id_type {\n webhooks::PayoutIdType::PayoutAttemptId(id) => db\n .find_payout_attempt_by_merchant_id_payout_attempt_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n webhooks::PayoutIdType::ConnectorPayoutId(id) => db\n .find_payout_attempt_by_merchant_id_connector_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout attempt\")?,\n },\n _ => Err(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"received a non-payout id when processing payout webhooks\")?,\n };\n\n let payouts = db\n .find_payout_by_merchant_id_payout_id(\n merchant_context.get_merchant_account().get_id(),\n &payout_attempt.payout_id,\n merchant_context.get_merchant_account().storage_scheme,\n )\n .await\n .change_context(errors::ApiErrorResponse::WebhookResourceNotFound)\n .attach_printable(\"Failed to fetch the payout\")?;\n\n let status = common_enums::PayoutStatus::foreign_try_from(event_type)\n .change_context(errors::ApiErrorResponse::WebhookProcessingFailure)\n .attach_printable(\"failed payout status mapping from event type\")?;\n\n let payout_webhook_details = connector\n .get_payout_webhook_details(request_details)\n .switch()\n .attach_printable(\"Failed to get error object for payouts\")?;\n\n // if status is failure then update the error_code and error_message as well\n let payout_attempt_update = if status.is_payout_failure() {\n PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status,\n error_message: payout_webhook_details.error_message,\n error_code: payout_webhook_details.error_code,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n }\n } else {\n PayoutAttemptUpdate::StatusUpdate {\n connector_payout_id: payout_attempt.connector_payout_id.clone(),\n status,\n error_message: None,\n error_code: None,\n is_eligible: payout_attempt.is_eligible,\n unified_code: None,\n unified_message: None,\n payout_connector_metadata: payout_attempt.payout_connector_metadata.clone(),\n }\n };\n"
71
+ },
72
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e",
73
+ "before_imports": [
74
+ "use hyperswitch_domain_models::{\n mandates::CommonMandateReference,\n payments::{payment_attempt::PaymentAttempt, HeaderPayload},\n router_request_types::VerifyWebhookSourceRequestData,\n router_response_types::{VerifyWebhookSourceResponseData, VerifyWebhookStatus},\n};",
75
+ "use common_utils::{\n errors::ReportSwitchExt,\n events::ApiEventsType,\n ext_traits::{AsyncExt, ByteSliceExt},\n types::{AmountConvertor, StringMinorUnitForConnector},\n};",
76
+ "use error_stack::{report, ResultExt};",
77
+ "use super::{types, utils, MERCHANT_ID};",
78
+ "use api_models::{\n enums::Connector,\n webhooks::{self, WebhookResponseTracker},\n};"
79
+ ],
80
+ "after_imports": [
81
+ "use hyperswitch_domain_models::{\n mandates::CommonMandateReference,\n payments::{payment_attempt::PaymentAttempt, HeaderPayload},\n router_request_types::VerifyWebhookSourceRequestData,\n router_response_types::{VerifyWebhookSourceResponseData, VerifyWebhookStatus},\n};",
82
+ "use common_utils::{\n errors::ReportSwitchExt,\n events::ApiEventsType,\n ext_traits::{AsyncExt, ByteSliceExt},\n types::{AmountConvertor, StringMinorUnitForConnector},\n};",
83
+ "use error_stack::{report, ResultExt};",
84
+ "use hyperswitch_interfaces::webhooks::{IncomingWebhookFlowError, IncomingWebhookRequestDetails};",
85
+ "use super::{types, utils, MERCHANT_ID};",
86
+ "use api_models::{\n enums::Connector,\n webhooks::{self, WebhookResponseTracker},\n};"
87
+ ]
88
+ },
89
+ {
90
+ "id": "crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs::struct::AdyenplatformIncomingWebhookData",
91
+ "file": "crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs",
92
+ "kind": "struct_item",
93
+ "status": "modified",
94
+ "code_changed": true,
95
+ "imports_changed": false,
96
+ "before_code": "pub struct AdyenplatformIncomingWebhookData {\n pub status: AdyenplatformWebhookStatus,\n pub reference: String,\n pub tracking: Option<AdyenplatformTrackingData>,\n pub category: Option<AdyenPayoutMethod>,\n}",
97
+ "after_code": "pub struct AdyenplatformIncomingWebhookData {\n pub status: AdyenplatformWebhookStatus,\n pub reference: String,\n pub tracking: Option<AdyenplatformTrackingData>,\n pub reason: Option<String>,\n pub category: Option<AdyenPayoutMethod>,\n}",
98
+ "diff_span": {
99
+ "before": "",
100
+ "after": " pub reference: String,\n pub tracking: Option<AdyenplatformTrackingData>,\n pub reason: Option<String>,\n pub category: Option<AdyenPayoutMethod>,\n}"
101
+ },
102
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
103
+ },
104
+ {
105
+ "id": "crates/common_enums/src/enums.rs::PayoutStatus::function::is_payout_failure",
106
+ "file": "crates/common_enums/src/enums.rs",
107
+ "kind": "function_item",
108
+ "status": "added",
109
+ "before_code": null,
110
+ "after_code": "pub fn is_payout_failure(&self) -> bool {\n matches!(\n self,\n Self::Failed | Self::Cancelled | Self::Expired | Self::Ineligible\n )\n }",
111
+ "diff_span": null,
112
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
113
+ },
114
+ {
115
+ "id": "crates/hyperswitch_interfaces/src/webhooks.rs::IncomingWebhook::function::get_payout_webhook_details",
116
+ "file": "crates/hyperswitch_interfaces/src/webhooks.rs",
117
+ "kind": "function_item",
118
+ "status": "added",
119
+ "before_code": null,
120
+ "after_code": "fn get_payout_webhook_details(\n &self,\n _request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::PayoutWebhookUpdate, errors::ConnectorError> {\n Ok(api_models::webhooks::PayoutWebhookUpdate {\n error_code: None,\n error_message: None,\n })\n }",
121
+ "diff_span": null,
122
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
123
+ },
124
+ {
125
+ "id": "crates/common_enums/src/enums.rs::impl::PayoutStatus",
126
+ "file": "crates/common_enums/src/enums.rs",
127
+ "kind": "impl_item",
128
+ "status": "added",
129
+ "before_code": null,
130
+ "after_code": "impl PayoutStatus {\n pub fn is_payout_failure(&self) -> bool {\n matches!(\n self,\n Self::Failed | Self::Cancelled | Self::Expired | Self::Ineligible\n )\n }\n}",
131
+ "diff_span": null,
132
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
133
+ },
134
+ {
135
+ "id": "crates/hyperswitch_connectors/src/connectors/adyenplatform.rs::Adyenplatform::function::get_payout_webhook_details",
136
+ "file": "crates/hyperswitch_connectors/src/connectors/adyenplatform.rs",
137
+ "kind": "function_item",
138
+ "status": "added",
139
+ "before_code": null,
140
+ "after_code": "fn get_payout_webhook_details(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::PayoutWebhookUpdate, ConnectorError> {\n let webhook_body: adyenplatform::AdyenplatformIncomingWebhook = request\n .body\n .parse_struct(\"AdyenplatformIncomingWebhook\")\n .change_context(ConnectorError::ResponseDeserializationFailed)?;\n\n let error_reason = webhook_body.data.reason.or(webhook_body\n .data\n .tracking\n .and_then(|tracking_data| tracking_data.reason));\n\n Ok(api_models::webhooks::PayoutWebhookUpdate {\n error_message: error_reason.clone(),\n error_code: error_reason,\n })\n }",
141
+ "diff_span": null,
142
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
143
+ },
144
+ {
145
+ "id": "crates/api_models/src/webhooks.rs::struct::PayoutWebhookUpdate",
146
+ "file": "crates/api_models/src/webhooks.rs",
147
+ "kind": "struct_item",
148
+ "status": "added",
149
+ "before_code": null,
150
+ "after_code": "pub struct PayoutWebhookUpdate {\n pub error_message: Option<String>,\n pub error_code: Option<String>,\n}",
151
+ "diff_span": null,
152
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
153
+ },
154
+ {
155
+ "id": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs::ConnectorEnum::function::get_payout_webhook_details",
156
+ "file": "crates/hyperswitch_interfaces/src/connector_integration_interface.rs",
157
+ "kind": "function_item",
158
+ "status": "added",
159
+ "before_code": null,
160
+ "after_code": "fn get_payout_webhook_details(\n &self,\n request: &IncomingWebhookRequestDetails<'_>,\n ) -> CustomResult<api_models::webhooks::PayoutWebhookUpdate, errors::ConnectorError> {\n match self {\n Self::Old(connector) => connector.get_payout_webhook_details(request),\n Self::New(connector) => connector.get_payout_webhook_details(request),\n }\n }",
161
+ "diff_span": null,
162
+ "commit_sha": "1aaa136f80f58082dce861be0015c4113ad43a9e"
163
+ }
164
+ ]
165
+ }
diffs/pr_10158/1df534e/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "1df534e8014a9011c5559dfe6b10f3e8c0b59ae6",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, &proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, &proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, &default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &default_metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": " if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, &proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, &proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, &default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &default_metrics_tag);\n Ok(client)\n }",
19
+ "after": " if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }"
20
+ },
21
+ "commit_sha": "1df534e8014a9011c5559dfe6b10f3e8c0b59ae6"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/1e044ba/diff.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::has_proxy_config",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }",
16
+ "after_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }",
17
+ "diff_span": {
18
+ "before": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }",
19
+ "after": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }"
20
+ },
21
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }",
31
+ "after_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"),\n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }",
32
+ "diff_span": {
33
+ "before": " \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),",
34
+ "after": " \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"),\n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),"
35
+ },
36
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9"
37
+ },
38
+ {
39
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
40
+ "file": "crates/external_services/src/http_client/client.rs",
41
+ "kind": "impl_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
46
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"),\n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
47
+ "diff_span": {
48
+ "before": " \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
49
+ "after": " \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"),\n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}"
50
+ },
51
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9"
52
+ },
53
+ {
54
+ "id": "crates/external_services/src/http_client/client.rs::function::get_client_builder",
55
+ "file": "crates/external_services/src/http_client/client.rs",
56
+ "kind": "function_item",
57
+ "status": "modified",
58
+ "code_changed": true,
59
+ "imports_changed": false,
60
+ "before_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
61
+ "after_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\n \"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\",\n proxy_config.http_url.clone(),\n proxy_config.https_url.clone()\n );\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
62
+ "diff_span": {
63
+ "before": " reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy",
64
+ "after": " reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\n \"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\",\n proxy_config.http_url.clone(),\n proxy_config.https_url.clone()\n );\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy"
65
+ },
66
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9"
67
+ },
68
+ {
69
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
70
+ "file": "crates/external_services/src/http_client/client.rs",
71
+ "kind": "function_item",
72
+ "status": "modified",
73
+ "code_changed": true,
74
+ "imports_changed": false,
75
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
76
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n\n // Create new proxy client if not in cache\n logger::info!(\n \"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\",\n cache_key,\n proxy_config.http_url,\n proxy_config.https_url\n );\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
77
+ "diff_span": {
78
+ "before": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)",
79
+ "after": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n\n // Create new proxy client if not in cache\n logger::info!(\n \"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\",\n cache_key,\n proxy_config.http_url,\n proxy_config.https_url\n );\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)"
80
+ },
81
+ "commit_sha": "1e044bae30e626a5bbd9d11c284ec489142bebb9"
82
+ }
83
+ ]
84
+ }
diffs/pr_10158/34cfedc/diff.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "34cfedce714b7380fc4a54ec951887e427cfdd82",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::create_new_proxy_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn create_new_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n Ok(new_client)\n }\n}",
16
+ "after_code": "fn create_new_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n Ok(new_client)\n }\n}",
17
+ "diff_span": {
18
+ "before": "\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);",
19
+ "after": "\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);"
20
+ },
21
+ "commit_sha": "34cfedce714b7380fc4a54ec951887e427cfdd82"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
31
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
32
+ "diff_span": {
33
+ "before": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {",
34
+ "after": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {"
35
+ },
36
+ "commit_sha": "34cfedce714b7380fc4a54ec951887e427cfdd82"
37
+ }
38
+ ]
39
+ }
diffs/pr_10158/381ff3b/diff.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "381ff3b050ae5d82ecb202e6b1da91b2ffb68ec8",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_or_create_proxy_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache.read().ok().and_then(|read_lock| read_lock.get(&cache_key).cloned());\n \n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n }\n }\n };\n\n Ok(client)\n}",
16
+ "after_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache\n .read()\n .ok()\n .and_then(|read_lock| read_lock.get(&cache_key).cloned());\n\n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n }\n }\n };\n\n Ok(client)\n}",
17
+ "diff_span": {
18
+ "before": " metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache.read().ok().and_then(|read_lock| read_lock.get(&cache_key).cloned());\n \n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);",
19
+ "after": " metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache\n .read()\n .ok()\n .and_then(|read_lock| read_lock.get(&cache_key).cloned());\n\n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);"
20
+ },
21
+ "commit_sha": "381ff3b050ae5d82ecb202e6b1da91b2ffb68ec8"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
31
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
32
+ "diff_span": {
33
+ "before": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n",
34
+ "after": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = get_or_create_proxy_client(cache, cache_key, proxy_config, metrics_tag)?;\n"
35
+ },
36
+ "commit_sha": "381ff3b050ae5d82ecb202e6b1da91b2ffb68ec8"
37
+ }
38
+ ]
39
+ }
diffs/pr_10158/3ea3282/diff.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "3ea32823bd5433539dff7506938a2f9bad369dbe",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::static::PROXY_CLIENT_CACHE",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "static_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();",
16
+ "after_code": "static PROXY_CLIENT_CACHE: OnceCell<RwLock<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();",
17
+ "diff_span": {
18
+ "before": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();",
19
+ "after": "static PROXY_CLIENT_CACHE: OnceCell<RwLock<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();"
20
+ },
21
+ "commit_sha": "3ea32823bd5433539dff7506938a2f9bad369dbe"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "function_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
31
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n \n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n \n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
32
+ "diff_span": {
33
+ "before": " let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n",
34
+ "after": " let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n \n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n \n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n"
35
+ },
36
+ "commit_sha": "3ea32823bd5433539dff7506938a2f9bad369dbe"
37
+ }
38
+ ]
39
+ }
diffs/pr_10158/4c4b7f4/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "4c4b7f405803091b02a01c5142cd9746402099bc",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n \n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n \n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n\n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n\n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n \n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n \n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n",
19
+ "after": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let read_lock = cache.read().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache read lock\")\n })?;\n\n let client = if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n\n let mut write_lock = cache.write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n"
20
+ },
21
+ "commit_sha": "4c4b7f405803091b02a01c5142cd9746402099bc"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/4f0c898/diff.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "4f0c8984b24f5f542dcf8cf7de11afeaea82fa9a",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_client_builder",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": true,
15
+ "before_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
16
+ "after_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
17
+ "diff_span": {
18
+ "before": "",
19
+ "after": " let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy"
20
+ },
21
+ "commit_sha": "4f0c8984b24f5f542dcf8cf7de11afeaea82fa9a",
22
+ "before_imports": [
23
+ "pub use common_utils::errors::CustomResult;",
24
+ "use std::time::Duration;"
25
+ ],
26
+ "after_imports": [
27
+ "use router_env::logger;",
28
+ "pub use common_utils::errors::CustomResult;",
29
+ "use std::time::Duration;"
30
+ ]
31
+ }
32
+ ]
33
+ }
diffs/pr_10158/575fed7/diff.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "575fed7bdcd9efa29fcf288f3dedc8d40daeebe5",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }",
16
+ "after_code": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Self {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }",
17
+ "diff_span": {
18
+ "before": " // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),",
19
+ "after": " // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Self {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),"
20
+ },
21
+ "commit_sha": "575fed7bdcd9efa29fcf288f3dedc8d40daeebe5"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "impl_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }\n}",
31
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Self {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }\n}",
32
+ "diff_span": {
33
+ "before": " // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),",
34
+ "after": " // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Self {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),"
35
+ },
36
+ "commit_sha": "575fed7bdcd9efa29fcf288f3dedc8d40daeebe5"
37
+ },
38
+ {
39
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
40
+ "file": "crates/external_services/src/http_client/client.rs",
41
+ "kind": "function_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
46
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
47
+ "diff_span": {
48
+ "before": " let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };",
49
+ "after": " let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n drop(read_lock);\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n }\n } else {\n create_new_proxy_client(cache, cache_key, proxy_config, metrics_tag)?\n };\n"
50
+ },
51
+ "commit_sha": "575fed7bdcd9efa29fcf288f3dedc8d40daeebe5"
52
+ },
53
+ {
54
+ "id": "crates/external_services/src/http_client/client.rs::function::create_new_proxy_client",
55
+ "file": "crates/external_services/src/http_client/client.rs",
56
+ "kind": "function_item",
57
+ "status": "added",
58
+ "before_code": null,
59
+ "after_code": "fn create_new_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(cached_client.clone())\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n Ok(new_client)\n }\n}",
60
+ "diff_span": null,
61
+ "commit_sha": "575fed7bdcd9efa29fcf288f3dedc8d40daeebe5"
62
+ }
63
+ ]
64
+ }
diffs/pr_10158/5a7fbf3/diff.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "5a7fbf30836f623facaf1a8e1d3fce5ddb06fd45",
3
+ "pr_number": 10158,
4
+ "rust_files": [],
5
+ "diffs": []
6
+ }
diffs/pr_10158/5e6a702/diff.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "5e6a70283ac8ca9f65326454abce0d95bfdf921a",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }",
16
+ "after_code": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }",
17
+ "diff_span": {
18
+ "before": " if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version",
19
+ "after": " if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version"
20
+ },
21
+ "commit_sha": "5e6a70283ac8ca9f65326454abce0d95bfdf921a"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "impl_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }\n}",
31
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }\n}",
32
+ "diff_span": {
33
+ "before": " if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version",
34
+ "after": " if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n\n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version"
35
+ },
36
+ "commit_sha": "5e6a70283ac8ca9f65326454abce0d95bfdf921a"
37
+ },
38
+ {
39
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
40
+ "file": "crates/external_services/src/http_client/client.rs",
41
+ "kind": "function_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
46
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
47
+ "diff_span": {
48
+ "before": " // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n",
49
+ "after": " // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n"
50
+ },
51
+ "commit_sha": "5e6a70283ac8ca9f65326454abce0d95bfdf921a"
52
+ }
53
+ ]
54
+ }
diffs/pr_10158/6f74057/diff.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "6f740570fdac6d8326d71fdf736be0e3c653eb0e",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs",
6
+ "crates/external_services/src/http_client/metrics.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
11
+ "file": "crates/external_services/src/http_client/client.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": true,
16
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone())\n }\n}",
17
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
18
+ "diff_span": {
19
+ "before": " \n // Use DEFAULT_CLIENT for non-proxy scenarios\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone())\n }\n}",
20
+ "after": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}"
21
+ },
22
+ "commit_sha": "6f740570fdac6d8326d71fdf736be0e3c653eb0e",
23
+ "before_imports": [
24
+ "use router_env::logger;",
25
+ "pub use common_utils::errors::CustomResult;"
26
+ ],
27
+ "after_imports": [
28
+ "use router_env::logger;",
29
+ "pub use common_utils::errors::CustomResult;",
30
+ "use super::metrics;"
31
+ ]
32
+ }
33
+ ]
34
+ }
diffs/pr_10158/784bb96/diff.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "784bb96edbe27fd4c558e2a02b8c758594ebe895",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
16
+ "after_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n\n logger::debug!(\n \"Generating cache key for proxy config: {:?}\",\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some()\n )\n );\n\n let mut hasher = DefaultHasher::new();\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some(),\n )\n .hash(&mut hasher);\n\n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n\n Some(cache_key)\n }",
17
+ "diff_span": {
18
+ "before": " return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
19
+ "after": " return None;\n }\n\n logger::debug!(\n \"Generating cache key for proxy config: {:?}\",\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some()\n )\n );\n\n let mut hasher = DefaultHasher::new();\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some(),\n )\n .hash(&mut hasher);\n\n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n\n Some(cache_key)\n }"
20
+ },
21
+ "commit_sha": "784bb96edbe27fd4c558e2a02b8c758594ebe895"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "impl_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
31
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n\n logger::debug!(\n \"Generating cache key for proxy config: {:?}\",\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some()\n )\n );\n\n let mut hasher = DefaultHasher::new();\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some(),\n )\n .hash(&mut hasher);\n\n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n\n Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
32
+ "diff_span": {
33
+ "before": " return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
34
+ "after": " return None;\n }\n\n logger::debug!(\n \"Generating cache key for proxy config: {:?}\",\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some()\n )\n );\n\n let mut hasher = DefaultHasher::new();\n (\n &self.http_url,\n &self.https_url,\n &self.bypass_proxy_hosts,\n self.mitm_ca_certificate.is_some(),\n )\n .hash(&mut hasher);\n\n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n\n Some(cache_key)\n }"
35
+ },
36
+ "commit_sha": "784bb96edbe27fd4c558e2a02b8c758594ebe895"
37
+ },
38
+ {
39
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
40
+ "file": "crates/external_services/src/http_client/client.rs",
41
+ "kind": "function_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
46
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\n \"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\",\n cache_key,\n proxy_config.http_url,\n proxy_config.https_url\n );\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
47
+ "diff_span": {
48
+ "before": " .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {",
49
+ "after": " .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n\n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\n \"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\",\n cache_key,\n proxy_config.http_url,\n proxy_config.https_url\n );\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n\n Ok(client)\n } else {"
50
+ },
51
+ "commit_sha": "784bb96edbe27fd4c558e2a02b8c758594ebe895"
52
+ }
53
+ ]
54
+ }
diffs/pr_10158/78b293b/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "78b293b5c26913f7c126e502cbf3ca20ec163ec8",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": " .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n \n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n",
19
+ "after": " .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n"
20
+ },
21
+ "commit_sha": "78b293b5c26913f7c126e502cbf3ca20ec163ec8"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/7fa4343/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "7fa4343a8a350f641b41f5846e9da72aa27ec883",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_or_create_proxy_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // First try read lock - fastest path for cache hits\n if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n }\n\n // Cache miss - need to create new client with write lock\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n \n Ok(new_client)\n}",
16
+ "after_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // First try read lock - fastest path for cache hits\n if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n }\n\n // Cache miss - need to create new client with write lock\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n \n Ok(new_client)\n}",
17
+ "diff_span": {
18
+ "before": " // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());",
19
+ "after": " // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());"
20
+ },
21
+ "commit_sha": "7fa4343a8a350f641b41f5846e9da72aa27ec883"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/90673b5/diff.json ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs",
6
+ "crates/external_services/src/http_client/metrics.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/external_services/src/http_client/client.rs::function::get_client_builder",
11
+ "file": "crates/external_services/src/http_client/client.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": false,
15
+ "imports_changed": true,
16
+ "before_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
17
+ "after_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
18
+ "diff_span": {
19
+ "before": "",
20
+ "after": ""
21
+ },
22
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d",
23
+ "before_imports": [
24
+ "pub use common_utils::errors::CustomResult;",
25
+ "use router_env::{logger, metric_attributes};"
26
+ ],
27
+ "after_imports": [
28
+ "use router_env::logger;",
29
+ "pub use common_utils::errors::CustomResult;"
30
+ ]
31
+ },
32
+ {
33
+ "id": "crates/external_services/src/http_client/client.rs::function::create_client",
34
+ "file": "crates/external_services/src/http_client/client.rs",
35
+ "kind": "function_item",
36
+ "status": "modified",
37
+ "code_changed": false,
38
+ "imports_changed": true,
39
+ "before_code": "pub fn create_client(\n proxy_config: &Proxy,\n client_certificate: Option<masking::Secret<String>>,\n client_certificate_key: Option<masking::Secret<String>>,\n ca_certificate: Option<masking::Secret<String>>,\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // Case 1: Mutual TLS with client certificate and key\n if let (Some(encoded_certificate), Some(encoded_certificate_key)) =\n (client_certificate.clone(), client_certificate_key.clone())\n {\n if ca_certificate.is_some() {\n logger::warn!(\"All of client certificate, client key, and CA certificate are provided. CA certificate will be ignored in mutual TLS setup.\");\n }\n\n logger::debug!(\"Creating HTTP client with mutual TLS (client cert + key)\");\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config);\n\n let identity = create_identity_from_certificate_and_key(\n encoded_certificate.clone(),\n encoded_certificate_key,\n )?;\n let certificate_list = create_certificate(encoded_certificate)?;\n let client_builder = certificate_list\n .into_iter()\n .fold(client_builder, |client_builder, certificate| {\n client_builder.add_root_certificate(certificate)\n });\n return client_builder\n .identity(identity)\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with certificate and certificate key\");\n }\n\n // Case 2: Use provided CA certificate for server authentication only (one-way TLS)\n if let Some(ca_pem) = ca_certificate {\n logger::debug!(\"Creating HTTP client with one-way TLS (CA certificate)\");\n let pem = ca_pem.expose().replace(\"\\\\r\\\\n\", \"\\n\"); // Fix escaped newlines\n let cert = reqwest::Certificate::from_pem(pem.as_bytes())\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to parse CA certificate PEM block\")?;\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .add_root_certificate(cert);\n return client_builder\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with CA certificate\");\n }\n\n // Case 3: Default client (no certs)\n logger::debug!(\"Creating default HTTP client (no client or CA certificates)\");\n get_base_client(proxy_config)\n}",
40
+ "after_code": "pub fn create_client(\n proxy_config: &Proxy,\n client_certificate: Option<masking::Secret<String>>,\n client_certificate_key: Option<masking::Secret<String>>,\n ca_certificate: Option<masking::Secret<String>>,\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // Case 1: Mutual TLS with client certificate and key\n if let (Some(encoded_certificate), Some(encoded_certificate_key)) =\n (client_certificate.clone(), client_certificate_key.clone())\n {\n if ca_certificate.is_some() {\n logger::warn!(\"All of client certificate, client key, and CA certificate are provided. CA certificate will be ignored in mutual TLS setup.\");\n }\n\n logger::debug!(\"Creating HTTP client with mutual TLS (client cert + key)\");\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config);\n\n let identity = create_identity_from_certificate_and_key(\n encoded_certificate.clone(),\n encoded_certificate_key,\n )?;\n let certificate_list = create_certificate(encoded_certificate)?;\n let client_builder = certificate_list\n .into_iter()\n .fold(client_builder, |client_builder, certificate| {\n client_builder.add_root_certificate(certificate)\n });\n return client_builder\n .identity(identity)\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with certificate and certificate key\");\n }\n\n // Case 2: Use provided CA certificate for server authentication only (one-way TLS)\n if let Some(ca_pem) = ca_certificate {\n logger::debug!(\"Creating HTTP client with one-way TLS (CA certificate)\");\n let pem = ca_pem.expose().replace(\"\\\\r\\\\n\", \"\\n\"); // Fix escaped newlines\n let cert = reqwest::Certificate::from_pem(pem.as_bytes())\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to parse CA certificate PEM block\")?;\n let client_builder =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .add_root_certificate(cert);\n return client_builder\n .use_rustls_tls()\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct client with CA certificate\");\n }\n\n // Case 3: Default client (no certs)\n logger::debug!(\"Creating default HTTP client (no client or CA certificates)\");\n get_base_client(proxy_config)\n}",
41
+ "diff_span": {
42
+ "before": "",
43
+ "after": ""
44
+ },
45
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d",
46
+ "before_imports": [
47
+ "pub use common_utils::errors::CustomResult;",
48
+ "use router_env::{logger, metric_attributes};"
49
+ ],
50
+ "after_imports": [
51
+ "use router_env::logger;",
52
+ "pub use common_utils::errors::CustomResult;"
53
+ ]
54
+ },
55
+ {
56
+ "id": "crates/external_services/src/http_client/client.rs::function::apply_mitm_certificate",
57
+ "file": "crates/external_services/src/http_client/client.rs",
58
+ "kind": "function_item",
59
+ "status": "modified",
60
+ "code_changed": false,
61
+ "imports_changed": true,
62
+ "before_code": "fn apply_mitm_certificate(\n mut client_builder: reqwest::ClientBuilder,\n proxy_config: &Proxy,\n) -> reqwest::ClientBuilder {\n if let Some(mitm_ca_cert) = &proxy_config.mitm_ca_certificate {\n let pem = mitm_ca_cert.clone().expose().replace(\"\\\\r\\\\n\", \"\\n\");\n match reqwest::Certificate::from_pem(pem.as_bytes()) {\n Ok(cert) => {\n logger::debug!(\"Successfully added MITM CA certificate\");\n client_builder = client_builder.add_root_certificate(cert);\n }\n Err(err) => {\n logger::error!(\n \"Failed to parse MITM CA certificate: {}, continuing without MITM support\",\n err\n );\n }\n }\n }\n client_builder\n}",
63
+ "after_code": "fn apply_mitm_certificate(\n mut client_builder: reqwest::ClientBuilder,\n proxy_config: &Proxy,\n) -> reqwest::ClientBuilder {\n if let Some(mitm_ca_cert) = &proxy_config.mitm_ca_certificate {\n let pem = mitm_ca_cert.clone().expose().replace(\"\\\\r\\\\n\", \"\\n\");\n match reqwest::Certificate::from_pem(pem.as_bytes()) {\n Ok(cert) => {\n logger::debug!(\"Successfully added MITM CA certificate\");\n client_builder = client_builder.add_root_certificate(cert);\n }\n Err(err) => {\n logger::error!(\n \"Failed to parse MITM CA certificate: {}, continuing without MITM support\",\n err\n );\n }\n }\n }\n client_builder\n}",
64
+ "diff_span": {
65
+ "before": "",
66
+ "after": ""
67
+ },
68
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d",
69
+ "before_imports": [
70
+ "use router_env::{logger, metric_attributes};"
71
+ ],
72
+ "after_imports": [
73
+ "use router_env::logger;"
74
+ ]
75
+ },
76
+ {
77
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
78
+ "file": "crates/external_services/src/http_client/client.rs",
79
+ "kind": "function_item",
80
+ "status": "modified",
81
+ "code_changed": true,
82
+ "imports_changed": true,
83
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}",
84
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone())\n }\n}",
85
+ "diff_span": {
86
+ "before": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}",
87
+ "after": " \n // Use DEFAULT_CLIENT for non-proxy scenarios\n Ok(DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone())\n }\n}"
88
+ },
89
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d",
90
+ "before_imports": [
91
+ "pub use common_utils::errors::CustomResult;",
92
+ "use super::metrics;",
93
+ "use router_env::{logger, metric_attributes};"
94
+ ],
95
+ "after_imports": [
96
+ "use router_env::logger;",
97
+ "pub use common_utils::errors::CustomResult;"
98
+ ]
99
+ },
100
+ {
101
+ "id": "crates/external_services/src/http_client/client.rs::function::extract_proxy_host",
102
+ "file": "crates/external_services/src/http_client/client.rs",
103
+ "kind": "function_item",
104
+ "status": "removed",
105
+ "before_code": "fn extract_proxy_host(url_opt: &Option<String>) -> String {\n url_opt.as_ref()\n .and_then(|url| url::Url::parse(url).ok())\n .and_then(|parsed_url| parsed_url.host_str().map(|s| s.to_string()))\n .unwrap_or_else(|| \"none\".to_string())\n}",
106
+ "after_code": null,
107
+ "diff_span": null,
108
+ "commit_sha": "90673b5ce716ba478601ddda6b445c772c18495d"
109
+ }
110
+ ]
111
+ }
diffs/pr_10158/9b8080e/diff.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "9b8080e6d6ca067563686dd9dc0d02d19d4f668c",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::has_proxy_config",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }",
16
+ "after_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }",
17
+ "diff_span": {
18
+ "before": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }",
19
+ "after": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }"
20
+ },
21
+ "commit_sha": "9b8080e6d6ca067563686dd9dc0d02d19d4f668c"
22
+ },
23
+ {
24
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
25
+ "file": "crates/external_services/src/http_client/client.rs",
26
+ "kind": "impl_item",
27
+ "status": "modified",
28
+ "code_changed": true,
29
+ "imports_changed": false,
30
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
31
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
32
+ "diff_span": {
33
+ "before": " Some(cache_key)\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
34
+ "after": " Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}"
35
+ },
36
+ "commit_sha": "9b8080e6d6ca067563686dd9dc0d02d19d4f668c"
37
+ },
38
+ {
39
+ "id": "crates/external_services/src/http_client/client.rs::function::get_client_builder",
40
+ "file": "crates/external_services/src/http_client/client.rs",
41
+ "kind": "function_item",
42
+ "status": "modified",
43
+ "code_changed": true,
44
+ "imports_changed": false,
45
+ "before_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
46
+ "after_code": "pub fn get_client_builder(\n proxy_config: &Proxy,\n) -> CustomResult<reqwest::ClientBuilder, HttpClientError> {\n let mut client_builder = reqwest::Client::builder()\n .redirect(reqwest::redirect::Policy::none())\n .pool_idle_timeout(Duration::from_secs(\n proxy_config\n .idle_pool_connection_timeout\n .unwrap_or_default(),\n ));\n\n let proxy_exclusion_config =\n reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\n \"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\",\n proxy_config.http_url.clone(),\n proxy_config.https_url.clone()\n );\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy\n if let Some(url) = proxy_config.https_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::https(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTPS proxy configuration error\")?\n .no_proxy(proxy_exclusion_config.clone()),\n );\n }\n\n // Proxy all HTTP traffic through the configured HTTP proxy\n if let Some(url) = proxy_config.http_url.as_ref() {\n client_builder = client_builder.proxy(\n reqwest::Proxy::http(url)\n .change_context(HttpClientError::InvalidProxyConfiguration)\n .attach_printable(\"HTTP proxy configuration error\")?\n .no_proxy(proxy_exclusion_config),\n );\n }\n\n Ok(client_builder)\n}",
47
+ "diff_span": {
48
+ "before": " reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\", proxy_config.http_url.clone(), proxy_config.https_url.clone());\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy",
49
+ "after": " reqwest::NoProxy::from_string(&proxy_config.bypass_proxy_hosts.clone().unwrap_or_default());\n\n logger::debug!(\n \"Proxy HTTP Proxy -> {:?} and HTTPS Proxy -> {:?}\",\n proxy_config.http_url.clone(),\n proxy_config.https_url.clone()\n );\n\n // Proxy all HTTPS traffic through the configured HTTPS proxy"
50
+ },
51
+ "commit_sha": "9b8080e6d6ca067563686dd9dc0d02d19d4f668c"
52
+ },
53
+ {
54
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
55
+ "file": "crates/external_services/src/http_client/client.rs",
56
+ "kind": "function_item",
57
+ "status": "modified",
58
+ "code_changed": true,
59
+ "imports_changed": false,
60
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
61
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
62
+ "diff_span": {
63
+ "before": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)",
64
+ "after": " if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)"
65
+ },
66
+ "commit_sha": "9b8080e6d6ca067563686dd9dc0d02d19d4f668c"
67
+ }
68
+ ]
69
+ }
diffs/pr_10158/a68697e/diff.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "a68697e1dec36b9655444366c76d27fc68d3c251",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": true,
15
+ "before_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }",
16
+ "after_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
17
+ "diff_span": {
18
+ "before": " return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }",
19
+ "after": " return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }"
20
+ },
21
+ "commit_sha": "a68697e1dec36b9655444366c76d27fc68d3c251",
22
+ "before_imports": [],
23
+ "after_imports": [
24
+ "use router_env::logger;"
25
+ ]
26
+ },
27
+ {
28
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
29
+ "file": "crates/external_services/src/http_client/client.rs",
30
+ "kind": "impl_item",
31
+ "status": "modified",
32
+ "code_changed": true,
33
+ "imports_changed": true,
34
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
35
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n \n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() \n || self.https_url.is_some() \n || self.mitm_ca_certificate.is_some()\n }\n}",
36
+ "diff_span": {
37
+ "before": " return None;\n }\n Some(format!(\n \"http:{}_https:{}_bypass:{}_timeout:{}_mitm:{}\",\n self.http_url.as_deref().unwrap_or(\"\"),\n self.https_url.as_deref().unwrap_or(\"\"), \n self.bypass_proxy_hosts.as_deref().unwrap_or(\"\"),\n self.idle_pool_connection_timeout.unwrap_or_default(),\n self.mitm_ca_certificate.is_some()\n ))\n }\n ",
38
+ "after": " return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n "
39
+ },
40
+ "commit_sha": "a68697e1dec36b9655444366c76d27fc68d3c251",
41
+ "before_imports": [],
42
+ "after_imports": [
43
+ "use router_env::logger;"
44
+ ]
45
+ },
46
+ {
47
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
48
+ "file": "crates/external_services/src/http_client/client.rs",
49
+ "kind": "function_item",
50
+ "status": "modified",
51
+ "code_changed": true,
52
+ "imports_changed": false,
53
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
54
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
55
+ "diff_span": {
56
+ "before": " })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {",
57
+ "after": " })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)"
58
+ },
59
+ "commit_sha": "a68697e1dec36b9655444366c76d27fc68d3c251"
60
+ }
61
+ ]
62
+ }
diffs/pr_10158/acdb837/diff.json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "acdb837550fa0673212ffa1ad59d88a58453a289",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs",
6
+ "crates/masking/src/secret.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/masking/src/secret.rs::hash_tests::function::test_secret_hash_implementation",
11
+ "file": "crates/masking/src/secret.rs",
12
+ "kind": "function_item",
13
+ "status": "modified",
14
+ "code_changed": false,
15
+ "imports_changed": true,
16
+ "before_code": "fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }",
17
+ "after_code": "fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }",
18
+ "diff_span": {
19
+ "before": "",
20
+ "after": ""
21
+ },
22
+ "commit_sha": "acdb837550fa0673212ffa1ad59d88a58453a289",
23
+ "before_imports": [
24
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
25
+ ],
26
+ "after_imports": [
27
+ "use std::hash::{DefaultHasher, Hash, Hasher};"
28
+ ]
29
+ },
30
+ {
31
+ "id": "crates/masking/src/secret.rs::mod::hash_tests",
32
+ "file": "crates/masking/src/secret.rs",
33
+ "kind": "mod_item",
34
+ "status": "modified",
35
+ "code_changed": true,
36
+ "imports_changed": true,
37
+ "before_code": "mod hash_tests {\n use std::hash::{Hash, Hasher, DefaultHasher};\n use super::*;\n\n #[test]\n fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }\n}",
38
+ "after_code": "mod hash_tests {\n use std::hash::{DefaultHasher, Hash, Hasher};\n\n use super::*;\n\n #[test]\n fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }\n}",
39
+ "diff_span": {
40
+ "before": "mod hash_tests {\n use std::hash::{Hash, Hasher, DefaultHasher};\n use super::*;\n",
41
+ "after": "mod hash_tests {\n use std::hash::{DefaultHasher, Hash, Hasher};\n\n use super::*;\n"
42
+ },
43
+ "commit_sha": "acdb837550fa0673212ffa1ad59d88a58453a289",
44
+ "before_imports": [
45
+ "use super::*;",
46
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
47
+ ],
48
+ "after_imports": [
49
+ "use std::hash::{DefaultHasher, Hash, Hasher};",
50
+ "use super::*;"
51
+ ]
52
+ },
53
+ {
54
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
55
+ "file": "crates/external_services/src/http_client/client.rs",
56
+ "kind": "function_item",
57
+ "status": "modified",
58
+ "code_changed": true,
59
+ "imports_changed": false,
60
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
61
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\n \"Using proxy-specific client cache with key: {:?}\",\n cache_key\n );\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client =\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n };\n\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
62
+ "diff_span": {
63
+ "before": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n \n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);",
64
+ "after": "\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| RwLock::new(HashMap::new()));\n\n let client = if let Some(cached_client) = cache.read().unwrap().get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);"
65
+ },
66
+ "commit_sha": "acdb837550fa0673212ffa1ad59d88a58453a289"
67
+ },
68
+ {
69
+ "id": "crates/masking/src/secret.rs::Secret<SecretValue, MaskingStrategy>::function::hash",
70
+ "file": "crates/masking/src/secret.rs",
71
+ "kind": "function_item",
72
+ "status": "modified",
73
+ "code_changed": false,
74
+ "imports_changed": true,
75
+ "before_code": "fn hash<H: std::hash::Hasher>(&self, state: &mut H) {\n self.peek().hash(state);\n }",
76
+ "after_code": "fn hash<H: std::hash::Hasher>(&self, state: &mut H) {\n self.peek().hash(state);\n }",
77
+ "diff_span": {
78
+ "before": "",
79
+ "after": ""
80
+ },
81
+ "commit_sha": "acdb837550fa0673212ffa1ad59d88a58453a289",
82
+ "before_imports": [
83
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
84
+ ],
85
+ "after_imports": [
86
+ "use std::hash::{DefaultHasher, Hash, Hasher};"
87
+ ]
88
+ }
89
+ ]
90
+ }
diffs/pr_10158/af4489c/diff.json ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "af4489c7c1a144b7121386e006af5839afffddc3",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/masking/src/secret.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/masking/src/secret.rs::hash_tests::function::test_secret_hash_implementation",
10
+ "file": "crates/masking/src/secret.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": false,
14
+ "imports_changed": true,
15
+ "before_code": "fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }",
16
+ "after_code": "fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }",
17
+ "diff_span": {
18
+ "before": "",
19
+ "after": ""
20
+ },
21
+ "commit_sha": "af4489c7c1a144b7121386e006af5839afffddc3",
22
+ "before_imports": [
23
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
24
+ ],
25
+ "after_imports": [
26
+ "use std::hash::{DefaultHasher, Hash, Hasher};"
27
+ ]
28
+ },
29
+ {
30
+ "id": "crates/masking/src/secret.rs::mod::hash_tests",
31
+ "file": "crates/masking/src/secret.rs",
32
+ "kind": "mod_item",
33
+ "status": "modified",
34
+ "code_changed": true,
35
+ "imports_changed": true,
36
+ "before_code": "mod hash_tests {\n use std::hash::{Hash, Hasher, DefaultHasher};\n use super::*;\n\n #[test]\n fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }\n}",
37
+ "after_code": "mod hash_tests {\n use std::hash::{DefaultHasher, Hash, Hasher};\n\n use super::*;\n\n #[test]\n fn test_secret_hash_implementation() {\n let secret1: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret2: Secret<String> = Secret::new(\"test_string\".to_string());\n let secret3: Secret<String> = Secret::new(\"different_string\".to_string());\n\n // Test that equal secrets hash to the same value\n let mut hasher1 = DefaultHasher::new();\n let mut hasher2 = DefaultHasher::new();\n secret1.hash(&mut hasher1);\n secret2.hash(&mut hasher2);\n assert_eq!(hasher1.finish(), hasher2.finish());\n\n // Test that different secrets hash to different values (usually)\n let mut hasher3 = DefaultHasher::new();\n secret3.hash(&mut hasher3);\n assert_ne!(hasher1.finish(), hasher3.finish());\n }\n}",
38
+ "diff_span": {
39
+ "before": "mod hash_tests {\n use std::hash::{Hash, Hasher, DefaultHasher};\n use super::*;\n",
40
+ "after": "mod hash_tests {\n use std::hash::{DefaultHasher, Hash, Hasher};\n\n use super::*;\n"
41
+ },
42
+ "commit_sha": "af4489c7c1a144b7121386e006af5839afffddc3",
43
+ "before_imports": [
44
+ "use super::*;",
45
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
46
+ ],
47
+ "after_imports": [
48
+ "use std::hash::{DefaultHasher, Hash, Hasher};",
49
+ "use super::*;"
50
+ ]
51
+ },
52
+ {
53
+ "id": "crates/masking/src/secret.rs::Secret<SecretValue, MaskingStrategy>::function::hash",
54
+ "file": "crates/masking/src/secret.rs",
55
+ "kind": "function_item",
56
+ "status": "modified",
57
+ "code_changed": false,
58
+ "imports_changed": true,
59
+ "before_code": "fn hash<H: std::hash::Hasher>(&self, state: &mut H) {\n self.peek().hash(state);\n }",
60
+ "after_code": "fn hash<H: std::hash::Hasher>(&self, state: &mut H) {\n self.peek().hash(state);\n }",
61
+ "diff_span": {
62
+ "before": "",
63
+ "after": ""
64
+ },
65
+ "commit_sha": "af4489c7c1a144b7121386e006af5839afffddc3",
66
+ "before_imports": [
67
+ "use std::hash::{Hash, Hasher, DefaultHasher};"
68
+ ],
69
+ "after_imports": [
70
+ "use std::hash::{DefaultHasher, Hash, Hasher};"
71
+ ]
72
+ }
73
+ ]
74
+ }
diffs/pr_10158/c1d8ffc/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "c1d8ffc66e4944c5a820e0ff749d9e1ceb46882b",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag.clone());\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag.clone());\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }\n}",
16
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n \n // Create simple metrics attributes for proxy client tracking\n let http_proxy_host = extract_proxy_host(&proxy_config.http_url);\n let https_proxy_host = extract_proxy_host(&proxy_config.https_url);\n \n let proxy_metrics_tag = metric_attributes!(\n (\"client_type\", \"proxy\"),\n (\"http_proxy_host\", http_proxy_host),\n (\"https_proxy_host\", https_proxy_host)\n );\n \n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, &proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, &proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, &default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &default_metrics_tag);\n Ok(client)\n }\n}",
17
+ "diff_span": {
18
+ "before": " if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, proxy_metrics_tag.clone());\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, default_metrics_tag.clone());\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, default_metrics_tag);\n Ok(client)\n }",
19
+ "after": " if let Some(client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &proxy_metrics_tag);\n return Ok(client.clone());\n }\n \n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, &proxy_metrics_tag);\n \n let client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, &proxy_metrics_tag);\n \n cache_lock.insert(cache_key.clone(), client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n \n let default_metrics_tag = metric_attributes!((\"client_type\", \"default\"));\n \n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, &default_metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n \n metrics::HTTP_CLIENT_CACHE_HIT.add(1, &default_metrics_tag);\n Ok(client)\n }"
20
+ },
21
+ "commit_sha": "c1d8ffc66e4944c5a820e0ff749d9e1ceb46882b"
22
+ }
23
+ ]
24
+ }
diffs/pr_10158/de60299/diff.json ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs",
6
+ "crates/hyperswitch_interfaces/src/types.rs"
7
+ ],
8
+ "diffs": [
9
+ {
10
+ "id": "crates/external_services/src/http_client/client.rs::trait::ProxyClientCacheKey",
11
+ "file": "crates/external_services/src/http_client/client.rs",
12
+ "kind": "trait_item",
13
+ "status": "modified",
14
+ "code_changed": true,
15
+ "imports_changed": false,
16
+ "before_code": "trait ProxyClientCacheKey {\n fn cache_key(&self) -> Option<String>;\n fn has_proxy_config(&self) -> bool;\n}",
17
+ "after_code": "trait ProxyClientCacheKey {\n fn cache_key(&self) -> Option<Proxy>;\n}",
18
+ "diff_span": {
19
+ "before": "trait ProxyClientCacheKey {\n fn cache_key(&self) -> Option<String>;\n fn has_proxy_config(&self) -> bool;\n}",
20
+ "after": "trait ProxyClientCacheKey {\n fn cache_key(&self) -> Option<Proxy>;\n}"
21
+ },
22
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
23
+ },
24
+ {
25
+ "id": "crates/external_services/src/http_client/client.rs::function::get_base_client",
26
+ "file": "crates/external_services/src/http_client/client.rs",
27
+ "kind": "function_item",
28
+ "status": "modified",
29
+ "code_changed": true,
30
+ "imports_changed": false,
31
+ "before_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
32
+ "after_code": "fn get_base_client(proxy_config: &Proxy) -> CustomResult<reqwest::Client, HttpClientError> {\n // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };\n \n Ok(client)\n } else {\n logger::debug!(\"No proxy configuration detected, using DEFAULT_CLIENT\");\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"default\"));\n\n // Use DEFAULT_CLIENT for non-proxy scenarios\n let client = DEFAULT_CLIENT\n .get_or_try_init(|| {\n logger::info!(\"Initializing DEFAULT_CLIENT (no proxy configuration)\");\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct default client\")\n })?\n .clone();\n\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n Ok(client)\n }\n}",
33
+ "diff_span": {
34
+ "before": " // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for key: {}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for key: {} (http_proxy: {:?}, https_proxy: {:?})\", \n cache_key, \n proxy_config.http_url, \n proxy_config.https_url\n );\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client with key: {}\", cache_key);\n new_client\n };",
35
+ "after": " // Check if proxy configuration is provided using trait method\n if let Some(cache_key) = proxy_config.cache_key() {\n logger::debug!(\"Using proxy-specific client cache with key: {:?}\", cache_key);\n\n let metrics_tag = router_env::metric_attributes!((\"client_type\", \"proxy\"));\n\n // Use proxy-specific client cache\n let cache = PROXY_CLIENT_CACHE.get_or_init(|| Mutex::new(HashMap::new()));\n let mut cache_lock = cache.lock().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache lock\")\n })?;\n \n let client = if let Some(cached_client) = cache_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n } else {\n // Create new proxy client if not in cache\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n \n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n \n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n \n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n \n cache_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n };"
36
+ },
37
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
38
+ },
39
+ {
40
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::cache_key",
41
+ "file": "crates/external_services/src/http_client/client.rs",
42
+ "kind": "function_item",
43
+ "status": "modified",
44
+ "code_changed": true,
45
+ "imports_changed": false,
46
+ "before_code": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
47
+ "after_code": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }",
48
+ "diff_span": {
49
+ "before": "fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }",
50
+ "after": "fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }"
51
+ },
52
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
53
+ },
54
+ {
55
+ "id": "crates/external_services/src/http_client/client.rs::static::PROXY_CLIENT_CACHE",
56
+ "file": "crates/external_services/src/http_client/client.rs",
57
+ "kind": "static_item",
58
+ "status": "modified",
59
+ "code_changed": true,
60
+ "imports_changed": false,
61
+ "before_code": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<String, reqwest::Client>>> = OnceCell::new();",
62
+ "after_code": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();",
63
+ "diff_span": {
64
+ "before": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<String, reqwest::Client>>> = OnceCell::new();",
65
+ "after": "static PROXY_CLIENT_CACHE: OnceCell<Mutex<HashMap<Proxy, reqwest::Client>>> = OnceCell::new();"
66
+ },
67
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
68
+ },
69
+ {
70
+ "id": "crates/external_services/src/http_client/client.rs::impl::Proxy",
71
+ "file": "crates/external_services/src/http_client/client.rs",
72
+ "kind": "impl_item",
73
+ "status": "modified",
74
+ "code_changed": true,
75
+ "imports_changed": false,
76
+ "before_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
77
+ "after_code": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }\n}",
78
+ "diff_span": {
79
+ "before": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<String> {\n if !self.has_proxy_config() {\n return None;\n }\n \n logger::debug!(\"Generating cache key for proxy config: {:?}\",\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some())\n );\n \n let mut hasher = DefaultHasher::new();\n (&self.http_url, &self.https_url, &self.bypass_proxy_hosts, self.mitm_ca_certificate.is_some()).hash(&mut hasher);\n \n let cache_key = format!(\"proxy_{:x}\", hasher.finish());\n logger::debug!(\"Generated cache key: {}\", cache_key);\n \n Some(cache_key)\n }\n\n fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }\n}",
80
+ "after": "impl ProxyClientCacheKey for Proxy {\n fn cache_key(&self) -> Option<Proxy> {\n if self.has_proxy_config() {\n logger::debug!(\"Using proxy config as cache key: {:?}\", self);\n \n // Return a clone of the proxy config for caching\n // Exclude timeout from cache key by creating a normalized version\n Some(Proxy {\n http_url: self.http_url.clone(),\n https_url: self.https_url.clone(),\n bypass_proxy_hosts: self.bypass_proxy_hosts.clone(),\n mitm_ca_certificate: self.mitm_ca_certificate.clone(),\n idle_pool_connection_timeout: None, // Exclude timeout from cache key\n mitm_enabled: self.mitm_enabled,\n })\n } else {\n None\n }\n }"
81
+ },
82
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
83
+ },
84
+ {
85
+ "id": "crates/hyperswitch_interfaces/src/types.rs::impl::Proxy",
86
+ "file": "crates/hyperswitch_interfaces/src/types.rs",
87
+ "kind": "impl_item",
88
+ "status": "modified",
89
+ "code_changed": true,
90
+ "imports_changed": false,
91
+ "before_code": "impl Default for Proxy {\n fn default() -> Self {\n Self {\n http_url: Default::default(),\n https_url: Default::default(),\n idle_pool_connection_timeout: Some(90),\n bypass_proxy_hosts: Default::default(),\n mitm_ca_certificate: None,\n mitm_enabled: None,\n }\n }\n}",
92
+ "after_code": "impl Proxy {\n /// Check if any proxy configuration is present\n pub fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some()\n }\n}",
93
+ "diff_span": {
94
+ "before": "impl Default for Proxy {\n fn default() -> Self {\n Self {\n http_url: Default::default(),\n https_url: Default::default(),\n idle_pool_connection_timeout: Some(90),\n bypass_proxy_hosts: Default::default(),\n mitm_ca_certificate: None,\n mitm_enabled: None,\n }\n }\n}",
95
+ "after": "impl Proxy {\n /// Check if any proxy configuration is present\n pub fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some()\n }\n}"
96
+ },
97
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
98
+ },
99
+ {
100
+ "id": "crates/hyperswitch_interfaces/src/types.rs::Proxy::function::has_proxy_config",
101
+ "file": "crates/hyperswitch_interfaces/src/types.rs",
102
+ "kind": "function_item",
103
+ "status": "added",
104
+ "before_code": null,
105
+ "after_code": "pub fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some()\n }",
106
+ "diff_span": null,
107
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
108
+ },
109
+ {
110
+ "id": "crates/external_services/src/http_client/client.rs::Proxy::function::has_proxy_config",
111
+ "file": "crates/external_services/src/http_client/client.rs",
112
+ "kind": "function_item",
113
+ "status": "removed",
114
+ "before_code": "fn has_proxy_config(&self) -> bool {\n self.http_url.is_some() || self.https_url.is_some() || self.mitm_ca_certificate.is_some()\n }",
115
+ "after_code": null,
116
+ "diff_span": null,
117
+ "commit_sha": "de60299a2a38cc7d3d237cbc8579b464ad0c008f"
118
+ }
119
+ ]
120
+ }
diffs/pr_10158/e5a739c/diff.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "commit_sha": "e5a739c9f4ab41e937772c3a646bfc65210819ef",
3
+ "pr_number": 10158,
4
+ "rust_files": [
5
+ "crates/external_services/src/http_client/client.rs"
6
+ ],
7
+ "diffs": [
8
+ {
9
+ "id": "crates/external_services/src/http_client/client.rs::function::get_or_create_proxy_client",
10
+ "file": "crates/external_services/src/http_client/client.rs",
11
+ "kind": "function_item",
12
+ "status": "modified",
13
+ "code_changed": true,
14
+ "imports_changed": false,
15
+ "before_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // First try read lock - fastest path for cache hits\n if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n }\n\n // Cache miss - need to create new client with write lock\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n \n Ok(new_client)\n}",
16
+ "after_code": "fn get_or_create_proxy_client(\n cache: &RwLock<HashMap<Proxy, reqwest::Client>>,\n cache_key: Proxy,\n proxy_config: &Proxy,\n metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache.read().ok().and_then(|read_lock| read_lock.get(&cache_key).cloned());\n \n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n }\n }\n };\n\n Ok(client)\n}",
17
+ "diff_span": {
18
+ "before": " metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n // First try read lock - fastest path for cache hits\n if let Ok(read_lock) = cache.read() {\n if let Some(cached_client) = read_lock.get(&cache_key) {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n }\n\n // Cache miss - need to create new client with write lock\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n // Double-check pattern: another thread might have created it\n if let Some(cached_client) = write_lock.get(&cache_key) {\n logger::debug!(\n \"Retrieved cached proxy client after write lock for config: {:?}\",\n cache_key\n );\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n return Ok(cached_client.clone());\n }\n\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n \n Ok(new_client)\n}",
19
+ "after": " metrics_tag: &[router_env::opentelemetry::KeyValue],\n) -> CustomResult<reqwest::Client, HttpClientError> {\n let read_result = cache.read().ok().and_then(|read_lock| read_lock.get(&cache_key).cloned());\n \n let client = match read_result {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client\n }\n None => {\n let mut write_lock = cache.try_write().map_err(|_| {\n error_stack::Report::new(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to acquire proxy client cache write lock\")\n })?;\n\n match write_lock.get(&cache_key) {\n Some(cached_client) => {\n logger::debug!(\"Retrieved cached proxy client after write lock for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_HIT.add(1, metrics_tag);\n cached_client.clone()\n }\n None => {\n logger::info!(\"Creating new proxy client for config: {:?}\", cache_key);\n metrics::HTTP_CLIENT_CACHE_MISS.add(1, metrics_tag);\n\n let new_client = apply_mitm_certificate(get_client_builder(proxy_config)?, proxy_config)\n .build()\n .change_context(HttpClientError::ClientConstructionFailed)\n .attach_printable(\"Failed to construct proxy client\")?;\n\n metrics::HTTP_CLIENT_CREATED.add(1, metrics_tag);\n write_lock.insert(cache_key.clone(), new_client.clone());\n logger::debug!(\"Cached new proxy client for config: {:?}\", cache_key);\n new_client\n }\n }\n }\n };\n\n Ok(client)\n}"
20
+ },
21
+ "commit_sha": "e5a739c9f4ab41e937772c3a646bfc65210819ef"
22
+ }
23
+ ]
24
+ }