diff --git a/src/model/sns.rs b/src/model/sns.rs index 552fe9b..688cd25 100644 --- a/src/model/sns.rs +++ b/src/model/sns.rs @@ -6,6 +6,19 @@ //! [0]: https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-json-formats.html use serde::Deserialize; +/// Union for all known SNS message types +/// +/// This type can be used to deserialize an arbitrary SNS message into the +/// appropriate type, based on the value of the `Type` field in the JSON +/// document. +#[derive(Deserialize)] +#[serde(tag = "Type")] +pub enum Message { + SubscriptionConfirmation(SubscriptionConfirmationMessage), + UnsubscribeConfirmation(UnsubscribeConfirmationMessage), + Notification(NotificationMessage), +} + /// SNS Subscription confirmation message /// /// See also: [HTTP/HTTPS subscription confirmation JSON format][0] @@ -14,8 +27,6 @@ use serde::Deserialize; #[derive(Deserialize)] #[serde(rename_all = "PascalCase")] pub struct SubscriptionConfirmationMessage { - #[serde(rename = "Type")] - pub message_type: String, #[serde(rename = "MessageId")] pub message_id: String, pub token: String, @@ -38,8 +49,6 @@ pub struct SubscriptionConfirmationMessage { #[derive(Deserialize)] #[serde(rename_all = "PascalCase")] pub struct NotificationMessage { - #[serde(rename = "Type")] - pub message_type: String, #[serde(rename = "MessageId")] pub message_id: String, pub topic_arn: String, @@ -61,8 +70,6 @@ pub struct NotificationMessage { #[derive(Deserialize)] #[serde(rename_all = "PascalCase")] pub struct UnsubscribeConfirmationMessage { - #[serde(rename = "Type")] - pub message_type: String, #[serde(rename = "MessageId")] pub message_id: String, pub token: String, diff --git a/src/sns/sig.rs b/src/sns/sig.rs index 0624cb4..382e5b7 100644 --- a/src/sns/sig.rs +++ b/src/sns/sig.rs @@ -171,7 +171,7 @@ impl SignatureVerifier for SubscriptionConfirmationMessage { s.push_str(&self.topic_arn); s.push('\n'); s.push_str("Type\n"); - s.push_str(&self.message_type); + s.push_str("SubscriptionConfirmation"); s.push('\n'); s } @@ -206,7 +206,7 @@ impl SignatureVerifier for NotificationMessage { s.push_str(&self.topic_arn); s.push('\n'); s.push_str("Type\n"); - s.push_str(&self.message_type); + s.push_str("Notification"); s.push('\n'); s } @@ -242,7 +242,7 @@ impl SignatureVerifier for UnsubscribeConfirmationMessage { s.push_str(&self.topic_arn); s.push('\n'); s.push_str("Type\n"); - s.push_str(&self.message_type); + s.push_str("UnsubscribeConfirmation"); s.push('\n'); s }