Skip to content

Commit aea390a

Browse files
prasunna09lsampras
andauthored
feat(events): add incoming webhook payload to api events logger (#2852)
Co-authored-by: Sampras lopes <[email protected]>
1 parent 375108b commit aea390a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+259
-202
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connector-template/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl api::IncomingWebhook for {{project-name | downcase | pascal_case}} {
485485
fn get_webhook_resource_object(
486486
&self,
487487
_request: &api::IncomingWebhookRequestDetails<'_>,
488-
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
488+
) -> CustomResult<Box<dyn erased_serde::Serialize>, errors::ConnectorError> {
489489
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
490490
}
491491
}

crates/common_utils/src/ext_traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub trait ByteSliceExt {
223223
}
224224

225225
impl ByteSliceExt for [u8] {
226+
#[track_caller]
226227
fn parse_struct<'de, T>(
227228
&'de self,
228229
type_name: &'static str,

crates/masking/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license.workspace = true
1010
[features]
1111
default = ["alloc", "serde", "diesel"]
1212
alloc = ["zeroize/alloc"]
13+
serde = ["dep:serde", "dep:serde_json"]
1314

1415
[package.metadata.docs.rs]
1516
all-features = true
@@ -19,7 +20,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1920
bytes = { version = "1", optional = true }
2021
diesel = { version = "2.1.0", features = ["postgres", "serde_json", "time"], optional = true }
2122
serde = { version = "1", features = ["derive"], optional = true }
22-
serde_json = "1.0.96"
23+
serde_json = { version = "1.0.96", optional = true }
2324
subtle = "=2.4.1"
2425
zeroize = { version = "1.6", default-features = false }
2526

crates/masking/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ mod vec;
4242
#[cfg(feature = "serde")]
4343
mod serde;
4444
#[cfg(feature = "serde")]
45-
pub use crate::serde::{masked_serialize, Deserialize, SerializableSecret, Serialize};
45+
pub use crate::serde::{
46+
masked_serialize, Deserialize, ErasedMaskSerialize, SerializableSecret, Serialize,
47+
};
4648

4749
/// This module should be included with asterisk.
4850
///

crates/masking/src/serde.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ pub fn masked_serialize<T: Serialize>(value: &T) -> Result<Value, serde_json::Er
9191
})
9292
}
9393

94+
///
95+
/// Masked serialization.
96+
///
97+
/// Trait object for supporting serialization to Value while accounting for masking
98+
/// The usual Serde Serialize trait cannot be used as trait objects
99+
/// like &dyn Serialize or boxed trait objects like Box<dyn Serialize> because of Rust's "object safety" rules.
100+
/// In particular, the trait contains generic methods which cannot be made into a trait object.
101+
/// In this case we remove the generic for assuming the serialization to be of 2 types only raw json or masked json
102+
pub trait ErasedMaskSerialize {
103+
/// Masked serialization.
104+
fn masked_serialize(&self) -> Result<Value, serde_json::Error>;
105+
/// Normal serialization.
106+
fn raw_serialize(&self) -> Result<Value, serde_json::Error>;
107+
}
108+
109+
impl<T: Serialize> ErasedMaskSerialize for T {
110+
fn masked_serialize(&self) -> Result<Value, serde_json::Error> {
111+
masked_serialize(self)
112+
}
113+
114+
fn raw_serialize(&self) -> Result<Value, serde_json::Error> {
115+
serde_json::to_value(self)
116+
}
117+
}
118+
94119
use pii_serializer::PIISerializer;
95120

96121
mod pii_serializer {

crates/router/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ router_derive = { version = "0.1.0", path = "../router_derive" }
115115
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }
116116
scheduler = { version = "0.1.0", path = "../scheduler", default-features = false }
117117
storage_impl = { version = "0.1.0", path = "../storage_impl", default-features = false }
118+
erased-serde = "0.3.31"
118119

119120
[build-dependencies]
120121
router_env = { version = "0.1.0", path = "../router_env", default-features = false }

crates/router/src/connector/aci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl api::IncomingWebhook for Aci {
572572
fn get_webhook_resource_object(
573573
&self,
574574
_request: &api::IncomingWebhookRequestDetails<'_>,
575-
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
575+
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
576576
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
577577
}
578578
}

crates/router/src/connector/adyen.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,17 +1600,13 @@ impl api::IncomingWebhook for Adyen {
16001600
fn get_webhook_resource_object(
16011601
&self,
16021602
request: &api::IncomingWebhookRequestDetails<'_>,
1603-
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
1603+
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
16041604
let notif = get_webhook_object_from_body(request.body)
16051605
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
16061606

16071607
let response: adyen::Response = notif.into();
16081608

1609-
let res_json = serde_json::to_value(response)
1610-
.into_report()
1611-
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
1612-
1613-
Ok(res_json)
1609+
Ok(Box::new(response))
16141610
}
16151611

16161612
fn get_webhook_api_response(

crates/router/src/connector/airwallex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,13 +1081,13 @@ impl api::IncomingWebhook for Airwallex {
10811081
fn get_webhook_resource_object(
10821082
&self,
10831083
request: &api::IncomingWebhookRequestDetails<'_>,
1084-
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
1084+
) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
10851085
let details: airwallex::AirwallexWebhookObjectResource = request
10861086
.body
10871087
.parse_struct("AirwallexWebhookObjectResource")
10881088
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
10891089

1090-
Ok(details.data.object)
1090+
Ok(Box::new(details.data.object))
10911091
}
10921092

10931093
fn get_dispute_details(

0 commit comments

Comments
 (0)