-
Notifications
You must be signed in to change notification settings - Fork 379
feat(lambda-events): add VPC Lattice event structures #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewpatto
wants to merge
11
commits into
aws:main
Choose a base branch
from
andrewpatto:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e4e616
Adding vpc lattice to Makefile
andrewpatto dc58b9f
Added lambda-event structures
andrewpatto 9a8aeef
First cut of new event jsons and structures
andrewpatto 1783450
fmt
andrewpatto 59da5b3
fix header serialize
andrewpatto 1c5f67a
nightly fmt
andrewpatto 20433dd
clippy fixes
andrewpatto 9e80c20
add basic response test
andrewpatto 2a81fd5
refactor(lambda-events): align VPC Lattice with library conventions
FullyTyped 24f4d71
fmt
FullyTyped 6c338a0
Update doc link
FullyTyped File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| use crate::{ | ||
| custom_serde::{deserialize_headers, serialize_headers}, | ||
| encodings::Body, | ||
| }; | ||
| use http::HeaderMap; | ||
| use serde::{Deserialize, Serialize}; | ||
| #[cfg(feature = "catch-all-fields")] | ||
| use serde_json::Value; | ||
|
|
||
| /// `VpcLatticeResponse` configures the response to be returned | ||
| /// by VPC Lattice (both V1 and V2) for the request | ||
| #[non_exhaustive] | ||
| #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct VpcLatticeResponse { | ||
| // https://docs.aws.amazon.com/vpc-lattice/latest/ug/lambda-functions.html#respond-to-service | ||
| /// Whether the body is base64 encoded | ||
| #[serde(default)] | ||
| pub is_base64_encoded: bool, | ||
|
|
||
| /// The HTTP status code for the request | ||
| // i64 for consistency with other event types (e.g. AlbTargetGroupResponse, ApiGatewayProxyResponse) | ||
| pub status_code: i64, | ||
|
|
||
| /// The HTTP status description (optional) | ||
| #[serde(default)] | ||
| pub status_description: Option<String>, | ||
|
|
||
| /// The Http headers to return | ||
| #[serde(deserialize_with = "deserialize_headers")] | ||
| #[serde(serialize_with = "serialize_headers")] | ||
| #[serde(skip_serializing_if = "HeaderMap::is_empty")] | ||
| #[serde(default)] | ||
| pub headers: HeaderMap, | ||
|
|
||
| /// The response body | ||
| #[serde(default)] | ||
| pub body: Option<Body>, | ||
|
|
||
| /// 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::*; | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "vpc_lattice")] | ||
| fn example_vpc_lattice_response() { | ||
| let data = include_bytes!("../../fixtures/example-vpc-lattice-response.json"); | ||
| let parsed: VpcLatticeResponse = serde_json::from_slice(data).unwrap(); | ||
| let output: String = serde_json::to_string(&parsed).unwrap(); | ||
| let reparsed: VpcLatticeResponse = serde_json::from_slice(output.as_bytes()).unwrap(); | ||
| assert_eq!(parsed, reparsed); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| mod common; | ||
| mod v1; | ||
| mod v2; | ||
|
|
||
| // re-export types | ||
| pub use self::{common::*, v1::*, v2::*}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| use http::{HeaderMap, Method}; | ||
| use query_map::QueryMap; | ||
| use serde::{Deserialize, Serialize}; | ||
| #[cfg(feature = "catch-all-fields")] | ||
| use serde_json::Value; | ||
|
|
||
| use crate::custom_serde::{ | ||
| deserialize_comma_separated_headers, deserialize_nullish_boolean, http_method, serialize_comma_separated_headers, | ||
| }; | ||
|
|
||
| /// `VpcLatticeRequestV1` contains data coming from VPC Lattice service (V1 format) | ||
| #[non_exhaustive] | ||
| #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] | ||
| // we note that V1 requests are snake cased UNLIKE v2 which are camel cased | ||
| #[serde(rename_all = "snake_case")] | ||
| pub struct VpcLatticeRequestV1 { | ||
| /// The url path for the request | ||
| #[serde(default)] | ||
| pub raw_path: Option<String>, | ||
|
|
||
| /// The HTTP method of the request | ||
| #[serde(with = "http_method")] | ||
| pub method: Method, | ||
|
|
||
| /// HTTP headers of the request (V1 uses comma-separated strings for multi-values) | ||
| #[serde(deserialize_with = "deserialize_comma_separated_headers", default)] | ||
| #[serde(serialize_with = "serialize_comma_separated_headers")] | ||
| pub headers: HeaderMap, | ||
|
|
||
| /// HTTP query string parameters (V1 uses the last value passed for multi-values | ||
| /// so no special serializer is needed) | ||
| #[serde(default)] | ||
| pub query_string_parameters: QueryMap, | ||
|
|
||
| /// The request body | ||
| #[serde(default)] | ||
| pub body: Option<String>, | ||
|
|
||
| /// Whether the body is base64 encoded | ||
| #[serde(default, deserialize_with = "deserialize_nullish_boolean")] | ||
| pub is_base64_encoded: bool, | ||
|
|
||
| /// Catchall to catch any additional fields | ||
| #[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::*; | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "vpc_lattice")] | ||
| fn example_vpc_lattice_v1_deserialize() { | ||
| let data = include_bytes!("../../fixtures/example-vpc-lattice-v1-request.json"); | ||
| let parsed: VpcLatticeRequestV1 = serde_json::from_slice(data).unwrap(); | ||
|
|
||
| assert_eq!("/api/product", parsed.raw_path.unwrap()); | ||
| assert_eq!("POST", parsed.method); | ||
| assert_eq!( | ||
| "curl/7.68.0", | ||
| parsed.headers.get_all("user-agent").iter().next().unwrap() | ||
| ); | ||
| assert_eq!("electronics", parsed.query_string_parameters.first("category").unwrap()); | ||
| assert_eq!("{\"id\": 5, \"description\": \"TV\"}", parsed.body.unwrap()); | ||
| assert!(!parsed.is_base64_encoded); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "vpc_lattice")] | ||
| fn example_vpc_lattice_v1_deserialize_headers_multi_values() { | ||
| let data = include_bytes!("../../fixtures/example-vpc-lattice-v1-request.json"); | ||
| let parsed: VpcLatticeRequestV1 = serde_json::from_slice(data).unwrap(); | ||
|
|
||
| assert_eq!("abcd", parsed.headers.get_all("multi").iter().next().unwrap()); | ||
| assert_eq!("DEF", parsed.headers.get_all("multi").iter().nth(1).unwrap()); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(feature = "vpc_lattice")] | ||
| fn example_vpc_lattice_v1_deserialize_query_string_map() { | ||
| let data = include_bytes!("../../fixtures/example-vpc-lattice-v1-request.json"); | ||
| let parsed: VpcLatticeRequestV1 = serde_json::from_slice(data).unwrap(); | ||
|
|
||
| assert_eq!("electronics", parsed.query_string_parameters.first("category").unwrap()); | ||
| assert_eq!("tv", parsed.query_string_parameters.first("tags").unwrap()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: oof it's a bit odd to use 64 bits for a http status code, I would have gone with u16. I guess it is a breaking change for the others, but maybe new events should use more efficient sizing?