forked from aws/aws-lambda-rust-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
205 lines (183 loc) · 7.3 KB
/
Copy pathmod.rs
File metadata and controls
205 lines (183 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
pub mod provider;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(tag = "RequestType")]
pub enum CloudFormationCustomResourceRequest<P1 = Value, P2 = Value>
where
P1: DeserializeOwned + Serialize,
P2: DeserializeOwned + Serialize,
{
#[serde(bound = "")]
Create(CreateRequest<P2>),
#[serde(bound = "")]
Update(UpdateRequest<P1, P2>),
#[serde(bound = "")]
Delete(DeleteRequest<P2>),
}
impl Default for CloudFormationCustomResourceRequest {
fn default() -> Self {
CloudFormationCustomResourceRequest::Create(CreateRequest::default())
}
}
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CreateRequest<P2 = Value>
where
P2: DeserializeOwned + Serialize,
{
#[serde(default)]
pub service_token: Option<String>,
pub request_id: String,
#[serde(rename = "ResponseURL")]
pub response_url: String,
pub stack_id: String,
pub resource_type: String,
pub logical_resource_id: String,
#[serde(bound = "")]
pub resource_properties: P2,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateRequest<P1 = Value, P2 = Value>
where
P1: DeserializeOwned + Serialize,
P2: DeserializeOwned + Serialize,
{
#[serde(default)]
pub service_token: Option<String>,
pub request_id: String,
#[serde(rename = "ResponseURL")]
pub response_url: String,
pub stack_id: String,
pub resource_type: String,
pub logical_resource_id: String,
pub physical_resource_id: String,
#[serde(bound = "")]
pub resource_properties: P2,
#[serde(bound = "")]
pub old_resource_properties: P1,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteRequest<P2 = Value>
where
P2: DeserializeOwned + Serialize,
{
#[serde(default)]
pub service_token: Option<String>,
pub request_id: String,
#[serde(rename = "ResponseURL")]
pub response_url: String,
pub stack_id: String,
pub resource_type: String,
pub logical_resource_id: String,
pub physical_resource_id: String,
#[serde(bound = "")]
pub resource_properties: P2,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct CloudFormationCustomResourceResponse {
pub status: CloudFormationCustomResourceResponseStatus,
pub reason: Option<String>,
pub physical_resource_id: String,
pub stack_id: String,
pub request_id: String,
pub logical_resource_id: String,
pub no_echo: bool,
pub data: HashMap<String, String>,
/// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
/// Enabled with Cargo feature `catch-all-fields`.
/// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
#[cfg(feature = "catch-all-fields")]
#[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
#[serde(flatten)]
pub other: serde_json::Map<String, Value>,
}
#[derive(Clone, Default, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CloudFormationCustomResourceResponseStatus {
#[default]
Success,
Failed,
}
#[cfg(test)]
mod test {
use std::collections::HashMap;
use super::{CloudFormationCustomResourceRequest::*, *};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
struct TestProperties {
key_1: String,
key_2: Vec<String>,
key_3: HashMap<String, String>,
}
type TestRequest = CloudFormationCustomResourceRequest<TestProperties, TestProperties>;
#[test]
fn example_cloudformation_custom_resource_create_request() {
let data = include_bytes!("../../fixtures/example-cloudformation-custom-resource-create-request.json");
let parsed: TestRequest = serde_json::from_slice(data).unwrap();
match parsed {
Create(_) => (),
_ => panic!("expected Create request"),
}
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: TestRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
fn example_cloudformation_custom_resource_update_request() {
let data = include_bytes!("../../fixtures/example-cloudformation-custom-resource-update-request.json");
let parsed: TestRequest = serde_json::from_slice(data).unwrap();
match parsed {
Update(_) => (),
_ => panic!("expected Update request"),
}
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: TestRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
fn example_cloudformation_custom_resource_delete_request() {
let data = include_bytes!("../../fixtures/example-cloudformation-custom-resource-delete-request.json");
let parsed: TestRequest = serde_json::from_slice(data).unwrap();
match parsed {
Delete(_) => (),
_ => panic!("expected Delete request"),
}
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: TestRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
fn example_cloudformation_custom_resource_response() {
let data = include_bytes!("../../fixtures/example-cloudformation-custom-resource-response.json");
let parsed: CloudFormationCustomResourceResponse = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: CloudFormationCustomResourceResponse = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}