Skip to content

Commit f213c51

Browse files
Chethan-raohyperswitch-bot[bot]srujanchikke
authored
chore: address Rust 1.77 clippy lints (#4172)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
1 parent 4c8cdf1 commit f213c51

File tree

16 files changed

+46
-105
lines changed

16 files changed

+46
-105
lines changed

add_connector.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,28 +514,23 @@ Within the `ConnectorIntegration` trait, you'll find the following methods imple
514514
}
515515
```
516516

517-
- `get_request_body` method calls transformers where hyperswitch payment request data is transformed into connector payment request. For constructing the request body have a function `log_and_get_request_body` that allows generic argument which is the struct that is passed as the body for connector integration, and a function that can be use to encode it into String. We log the request in this function, as the struct will be intact and the masked values will be masked.
517+
- `get_request_body` method calls transformers where hyperswitch payment request data is transformed into connector payment request. If the conversion and construction processes are successful, the function wraps the constructed connector_req in a Box and returns it as `RequestContent::Json`. The `RequestContent` enum defines different types of request content that can be sent. It includes variants for JSON, form-urlencoded, XML, raw bytes, and potentially other formats.
518518

519519
```rust
520520
fn get_request_body(
521-
&self,
522-
req: &types::PaymentsAuthorizeRouterData,
523-
_connectors: &settings::Connectors,
524-
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
525-
let connector_router_data = checkout::CheckoutRouterData::try_from((
526-
&self.get_currency_unit(),
527-
req.request.currency,
528-
req.request.amount,
529-
req,
530-
))?;
531-
let connector_req = checkout::PaymentsRequest::try_from(&connector_router_data)?;
532-
let checkout_req = types::RequestBody::log_and_get_request_body(
533-
&connector_req,
534-
utils::Encode::encode_to_string_of_json,
535-
)
536-
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
537-
Ok(Some(checkout_req))
538-
}
521+
&self,
522+
req: &types::PaymentsAuthorizeRouterData,
523+
_connectors: &settings::Connectors,
524+
) -> CustomResult<RequestContent, errors::ConnectorError> {
525+
let connector_router_data = checkout::CheckoutRouterData::try_from((
526+
&self.get_currency_unit(),
527+
req.request.currency,
528+
req.request.amount,
529+
req,
530+
))?;
531+
let connector_req = checkout::PaymentsRequest::try_from(&connector_router_data)?;
532+
Ok(RequestContent::Json(Box::new(connector_req)))
533+
}
539534
```
540535

541536
- `build_request` method assembles the API request by providing the method, URL, headers, and request body as parameters.

crates/common_utils/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ pub mod date_time {
3535
},
3636
OffsetDateTime, PrimitiveDateTime,
3737
};
38-
/// Struct to represent milliseconds in time sensitive data fields
39-
#[derive(Debug)]
40-
pub struct Milliseconds(i32);
4138

4239
/// Enum to represent date formats
4340
#[derive(Debug)]

crates/common_utils/src/request.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use masking::{Maskable, Secret};
2-
#[cfg(feature = "logs")]
3-
use router_env::logger;
42
use serde::{Deserialize, Serialize};
53

6-
use crate::errors;
7-
84
pub type Headers = std::collections::HashSet<(String, Maskable<String>)>;
95

106
#[derive(
@@ -64,6 +60,18 @@ pub enum RequestContent {
6460
RawBytes(Vec<u8>),
6561
}
6662

63+
impl RequestContent {
64+
pub fn get_inner_value(&self) -> Secret<String> {
65+
match self {
66+
Self::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(),
67+
Self::FormUrlEncoded(i) => serde_urlencoded::to_string(i).unwrap_or_default().into(),
68+
Self::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(),
69+
Self::FormData(_) => String::new().into(),
70+
Self::RawBytes(_) => String::new().into(),
71+
}
72+
}
73+
}
74+
6775
impl Request {
6876
pub fn new(method: Method, url: &str) -> Self {
6977
Self {
@@ -176,33 +184,3 @@ impl Default for RequestBuilder {
176184
Self::new()
177185
}
178186
}
179-
180-
#[derive(Clone, Debug)]
181-
pub struct RequestBody(Secret<String>);
182-
183-
impl RequestBody {
184-
pub fn log_and_get_request_body<T, F>(
185-
body: T,
186-
encoder: F,
187-
) -> errors::CustomResult<Self, errors::ParsingError>
188-
where
189-
F: FnOnce(T) -> errors::CustomResult<String, errors::ParsingError>,
190-
T: std::fmt::Debug,
191-
{
192-
#[cfg(feature = "logs")]
193-
logger::info!(connector_request_body=?body);
194-
Ok(Self(Secret::new(encoder(body)?)))
195-
}
196-
197-
pub fn get_inner_value(request_body: RequestContent) -> Secret<String> {
198-
match request_body {
199-
RequestContent::Json(i) => serde_json::to_string(&i).unwrap_or_default().into(),
200-
RequestContent::FormUrlEncoded(i) => {
201-
serde_urlencoded::to_string(&i).unwrap_or_default().into()
202-
}
203-
RequestContent::Xml(i) => quick_xml::se::to_string(&i).unwrap_or_default().into(),
204-
RequestContent::FormData(_) => String::new().into(),
205-
RequestContent::RawBytes(_) => String::new().into(),
206-
}
207-
}
208-
}

crates/diesel_models/src/process_tracker.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,6 @@ impl From<ProcessTrackerUpdate> for ProcessTrackerUpdateInternal {
190190
}
191191
}
192192

193-
#[allow(dead_code)]
194-
pub struct SchedulerOptions {
195-
looper_interval: common_utils::date_time::Milliseconds,
196-
db_name: String,
197-
cache_name: String,
198-
schema_name: String,
199-
cache_expiry: i32,
200-
runners: Vec<String>,
201-
fetch_limit: i32,
202-
fetch_limit_product_factor: i32,
203-
query_order: String,
204-
}
205-
206-
#[derive(Debug, Clone)]
207-
#[allow(dead_code)]
208-
pub struct ProcessData {
209-
db_name: String,
210-
cache_name: String,
211-
process_tracker: ProcessTracker,
212-
}
213-
214193
#[derive(
215194
serde::Serialize,
216195
serde::Deserialize,

crates/router/src/connector/bankofamerica.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,7 @@ where
140140
.chars()
141141
.skip(base_url.len() - 1)
142142
.collect();
143-
let sha256 = self.generate_digest(
144-
types::RequestBody::get_inner_value(boa_req)
145-
.expose()
146-
.as_bytes(),
147-
);
143+
let sha256 = self.generate_digest(boa_req.get_inner_value().expose().as_bytes());
148144
let signature = self.generate_signature(
149145
auth,
150146
host.to_string(),

crates/router/src/connector/checkout/transformers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ pub fn construct_file_upload_request(
13451345
request.file_key,
13461346
request
13471347
.file_type
1348-
.to_string()
1348+
.as_ref()
13491349
.split('/')
13501350
.last()
13511351
.unwrap_or_default()

crates/router/src/connector/cryptopay.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ where
7777
| common_utils::request::Method::Put
7878
| common_utils::request::Method::Delete
7979
| common_utils::request::Method::Patch => {
80-
let body =
81-
types::RequestBody::get_inner_value(self.get_request_body(req, connectors)?)
82-
.peek()
83-
.to_owned();
80+
let body = self
81+
.get_request_body(req, connectors)?
82+
.get_inner_value()
83+
.peek()
84+
.to_owned();
8485
let md5_payload = crypto::Md5
8586
.generate_digest(body.as_bytes())
8687
.change_context(errors::ConnectorError::RequestEncodingFailed)?;

crates/router/src/connector/cybersource.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ where
241241
.chars()
242242
.skip(base_url.len() - 1)
243243
.collect();
244-
let sha256 = self.generate_digest(
245-
types::RequestBody::get_inner_value(cybersource_req)
246-
.expose()
247-
.as_bytes(),
248-
);
244+
let sha256 = self.generate_digest(cybersource_req.get_inner_value().expose().as_bytes());
249245
let http_method = self.get_http_method();
250246
let signature = self.generate_signature(
251247
auth,

crates/router/src/connector/dlocal.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ where
6868
"{}{}{}",
6969
auth.x_login.peek(),
7070
date,
71-
types::RequestBody::get_inner_value(dlocal_req)
72-
.peek()
73-
.to_owned()
71+
dlocal_req.get_inner_value().peek().to_owned()
7472
);
7573
let authz = crypto::HmacSha256::sign_message(
7674
&crypto::HmacSha256,

crates/router/src/connector/fiserv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
.generate_authorization_signature(
7979
auth,
8080
&client_request_id,
81-
types::RequestBody::get_inner_value(fiserv_req).peek(),
81+
fiserv_req.get_inner_value().peek(),
8282
timestamp,
8383
)
8484
.change_context(errors::ConnectorError::RequestEncodingFailed)?;

0 commit comments

Comments
 (0)