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
153 lines (144 loc) · 6.74 KB
/
Copy pathmod.rs
File metadata and controls
153 lines (144 loc) · 6.74 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
use crate::{
custom_serde::{
deserialize_headers, deserialize_nullish_boolean, http_method, serialize_headers,
serialize_multi_value_headers, serialize_query_string_parameters,
},
encodings::Body,
};
use http::{HeaderMap, Method};
use query_map::QueryMap;
use serde::{Deserialize, Serialize};
#[cfg(feature = "catch-all-fields")]
use serde_json::Value;
/// `AlbTargetGroupRequest` contains data originating from the ALB Lambda target group integration
#[non_exhaustive]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AlbTargetGroupRequest {
#[serde(with = "http_method")]
pub http_method: Method,
#[serde(default)]
pub path: Option<String>,
#[serde(default)]
#[serde(serialize_with = "serialize_query_string_parameters")]
pub query_string_parameters: QueryMap,
#[serde(default)]
pub multi_value_query_string_parameters: QueryMap,
#[serde(deserialize_with = "deserialize_headers", default)]
#[serde(serialize_with = "serialize_headers")]
pub headers: HeaderMap,
#[serde(deserialize_with = "deserialize_headers", default)]
#[serde(serialize_with = "serialize_multi_value_headers")]
pub multi_value_headers: HeaderMap,
pub request_context: AlbTargetGroupRequestContext,
#[serde(default, deserialize_with = "deserialize_nullish_boolean")]
pub is_base64_encoded: bool,
pub body: Option<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>,
}
/// `AlbTargetGroupRequestContext` contains the information to identify the load balancer invoking the lambda
#[non_exhaustive]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AlbTargetGroupRequestContext {
pub elb: ElbContext,
/// 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>,
}
/// `ElbContext` contains the information to identify the ARN invoking the lambda
#[non_exhaustive]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ElbContext {
/// nolint: stylecheck
#[serde(default)]
pub target_group_arn: Option<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>,
}
/// `AlbTargetGroupResponse` configures the response to be returned by the ALB Lambda target group for the request
#[non_exhaustive]
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AlbTargetGroupResponse {
pub status_code: i64,
#[serde(default)]
pub status_description: Option<String>,
#[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
#[serde(serialize_with = "serialize_headers")]
pub headers: HeaderMap,
#[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
#[serde(serialize_with = "serialize_multi_value_headers")]
pub multi_value_headers: HeaderMap,
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<Body>,
#[serde(default, deserialize_with = "deserialize_nullish_boolean")]
pub is_base64_encoded: bool,
/// 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>,
}
#[cfg(test)]
mod test {
use super::*;
use serde_json::Value;
#[test]
#[cfg(feature = "alb")]
fn example_alb_lambda_target_request_headers_only() {
let data = include_bytes!("../../fixtures/example-alb-lambda-target-request-headers-only.json");
let parsed: AlbTargetGroupRequest = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AlbTargetGroupRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "alb")]
fn example_alb_lambda_target_request_multivalue_headers() {
let data = include_bytes!("../../fixtures/example-alb-lambda-target-request-multivalue-headers.json");
let parsed: AlbTargetGroupRequest = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AlbTargetGroupRequest = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
#[test]
#[cfg(feature = "alb")]
fn ensure_alb_lambda_target_request_query_string_parameter_value_is_string() {
let data = include_bytes!("../../fixtures/example-alb-lambda-target-request-headers-only.json");
let parsed: AlbTargetGroupRequest = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: Value = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(
reparsed["queryStringParameters"]["key"],
Value::String("hello".to_string())
);
}
#[test]
#[cfg(feature = "alb")]
fn example_alb_lambda_target_response() {
let data = include_bytes!("../../fixtures/example-alb-lambda-target-response.json");
let parsed: AlbTargetGroupResponse = serde_json::from_slice(data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AlbTargetGroupResponse = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}