-
Notifications
You must be signed in to change notification settings - Fork 242
feat(runtime-interface-client): Add Lambda-Runtime-Invocation-Id support for cross-wiring protection #624
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
base: main
Are you sure you want to change the base?
feat(runtime-interface-client): Add Lambda-Runtime-Invocation-Id support for cross-wiring protection #624
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ static constexpr auto COGNITO_IDENTITY_HEADER = "lambda-runtime-cognito-identity | |
| static constexpr auto DEADLINE_MS_HEADER = "lambda-runtime-deadline-ms"; | ||
| static constexpr auto FUNCTION_ARN_HEADER = "lambda-runtime-invoked-function-arn"; | ||
| static constexpr auto TENANT_ID_HEADER = "lambda-runtime-aws-tenant-id"; | ||
| static constexpr auto INVOCATION_ID_HEADER = "lambda-runtime-invocation-id"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "L" is capitalised in the java file but lowercase here |
||
| thread_local static CURL* m_curl_handle = curl_easy_init(); | ||
|
|
||
| enum Endpoints { | ||
|
|
@@ -306,25 +307,30 @@ runtime::next_outcome runtime::get_next() | |
| if (resp.has_header(TENANT_ID_HEADER)) { | ||
| req.tenant_id = resp.get_header(TENANT_ID_HEADER); | ||
| } | ||
|
|
||
| if (resp.has_header(INVOCATION_ID_HEADER)) { | ||
| req.invocation_id = resp.get_header(INVOCATION_ID_HEADER); | ||
| } | ||
| return next_outcome(req); | ||
| } | ||
|
|
||
| runtime::post_outcome runtime::post_success(std::string const& request_id, invocation_response const& handler_response) | ||
| runtime::post_outcome runtime::post_success(std::string const& request_id, invocation_response const& handler_response, std::string const& invocation_id) | ||
| { | ||
| std::string const url = m_endpoints[Endpoints::RESULT] + request_id + "/response"; | ||
| return do_post(url, request_id, handler_response); | ||
| return do_post(url, request_id, handler_response, invocation_id); | ||
| } | ||
|
|
||
| runtime::post_outcome runtime::post_failure(std::string const& request_id, invocation_response const& handler_response) | ||
| runtime::post_outcome runtime::post_failure(std::string const& request_id, invocation_response const& handler_response, std::string const& invocation_id) | ||
| { | ||
| std::string const url = m_endpoints[Endpoints::RESULT] + request_id + "/error"; | ||
| return do_post(url, request_id, handler_response); | ||
| return do_post(url, request_id, handler_response, invocation_id); | ||
| } | ||
|
|
||
| runtime::post_outcome runtime::do_post( | ||
| std::string const& url, | ||
| std::string const& request_id, | ||
| invocation_response const& handler_response) | ||
| invocation_response const& handler_response, | ||
| std::string const& invocation_id) | ||
| { | ||
| set_curl_post_result_options(); | ||
| curl_easy_setopt(lambda_runtime::m_curl_handle, CURLOPT_URL, url.c_str()); | ||
|
|
@@ -341,6 +347,9 @@ runtime::post_outcome runtime::do_post( | |
| headers = curl_slist_append(headers, "Expect:"); | ||
| headers = curl_slist_append(headers, "transfer-encoding:"); | ||
| headers = curl_slist_append(headers, m_user_agent_header.c_str()); | ||
| if (!invocation_id.empty()) { | ||
| headers = curl_slist_append(headers, ("lambda-runtime-invocation-id: " + invocation_id).c_str()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use the header constant here instead of hardcoding again? |
||
| } | ||
| auto const& payload = handler_response.get_payload(); | ||
| logging::log_debug( | ||
| LOG_TAG, "calculating content length... %s", ("content-length: " + std::to_string(payload.length())).c_str()); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same feedback for positive path test inclusion as in this file LambdaRuntimeApiClientImplTest.java |
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.
the other headers in this file are declared as constants at the start of the file. I would suggest keeping that uniform and making a constant above for this one as well