model: sns: Add union type
The `model::sns::Message` enumeration provides a mechanism for deserializing a JSON document into the correct type. It will be used by the HTTP operation that receives messages from SNS in order to determine the correct action to take in response to the message.master
parent
196a43c49c
commit
3ce72623e6
|
@ -6,6 +6,19 @@
|
||||||
//! [0]: https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-json-formats.html
|
//! [0]: https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-json-formats.html
|
||||||
use serde::Deserialize;
|
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
|
/// SNS Subscription confirmation message
|
||||||
///
|
///
|
||||||
/// See also: [HTTP/HTTPS subscription confirmation JSON format][0]
|
/// See also: [HTTP/HTTPS subscription confirmation JSON format][0]
|
||||||
|
@ -14,8 +27,6 @@ use serde::Deserialize;
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct SubscriptionConfirmationMessage {
|
pub struct SubscriptionConfirmationMessage {
|
||||||
#[serde(rename = "Type")]
|
|
||||||
pub message_type: String,
|
|
||||||
#[serde(rename = "MessageId")]
|
#[serde(rename = "MessageId")]
|
||||||
pub message_id: String,
|
pub message_id: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
@ -38,8 +49,6 @@ pub struct SubscriptionConfirmationMessage {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct NotificationMessage {
|
pub struct NotificationMessage {
|
||||||
#[serde(rename = "Type")]
|
|
||||||
pub message_type: String,
|
|
||||||
#[serde(rename = "MessageId")]
|
#[serde(rename = "MessageId")]
|
||||||
pub message_id: String,
|
pub message_id: String,
|
||||||
pub topic_arn: String,
|
pub topic_arn: String,
|
||||||
|
@ -61,8 +70,6 @@ pub struct NotificationMessage {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct UnsubscribeConfirmationMessage {
|
pub struct UnsubscribeConfirmationMessage {
|
||||||
#[serde(rename = "Type")]
|
|
||||||
pub message_type: String,
|
|
||||||
#[serde(rename = "MessageId")]
|
#[serde(rename = "MessageId")]
|
||||||
pub message_id: String,
|
pub message_id: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
|
|
@ -171,7 +171,7 @@ impl SignatureVerifier for SubscriptionConfirmationMessage {
|
||||||
s.push_str(&self.topic_arn);
|
s.push_str(&self.topic_arn);
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s.push_str("Type\n");
|
s.push_str("Type\n");
|
||||||
s.push_str(&self.message_type);
|
s.push_str("SubscriptionConfirmation");
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ impl SignatureVerifier for NotificationMessage {
|
||||||
s.push_str(&self.topic_arn);
|
s.push_str(&self.topic_arn);
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s.push_str("Type\n");
|
s.push_str("Type\n");
|
||||||
s.push_str(&self.message_type);
|
s.push_str("Notification");
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ impl SignatureVerifier for UnsubscribeConfirmationMessage {
|
||||||
s.push_str(&self.topic_arn);
|
s.push_str(&self.topic_arn);
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s.push_str("Type\n");
|
s.push_str("Type\n");
|
||||||
s.push_str(&self.message_type);
|
s.push_str("UnsubscribeConfirmation");
|
||||||
s.push('\n');
|
s.push('\n');
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue