Skip to content
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

Fix: orchestrator flow #2699

Merged
merged 25 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fb84a12
progress check-in
Velfi May 8, 2023
01d0acd
it's close, but I have to figure out how to call the final intercepto…
Velfi May 10, 2023
b9e2bb3
it lives! not all tests are passing yet, though
Velfi May 12, 2023
790111f
all tests passing!!!
Velfi May 12, 2023
2b8c294
Merge remote-tracking branch 'origin/main' into fix/orchestrator-flow
Velfi May 12, 2023
7adf8d5
update: define the context wrappers using a macro
Velfi May 15, 2023
45944a6
fix: compilation errors resulting from context wrapper change
Velfi May 16, 2023
ea1756f
fix: missing generics in codegen
Velfi May 16, 2023
f777f1d
update: make public some types linked in the docs
Velfi May 16, 2023
5e829e1
Merge branch 'main' into fix/orchestrator-flow
Velfi May 16, 2023
236cae7
add: error enum for orchestrator errors
Velfi May 16, 2023
9c2a6b4
fix: broken test
Velfi May 16, 2023
a8ee5e5
run `cargo clippy --fix`
Velfi May 16, 2023
8dd284d
fix: codegen
Velfi May 16, 2023
53e9820
update: is_failed to check the inner output_or_error
Velfi May 17, 2023
a1b02ab
Merge branch 'main' into fix/orchestrator-flow
Velfi May 17, 2023
d903354
remove redundant generic type parameters
Velfi May 17, 2023
190f5e8
remove unused import
Velfi May 17, 2023
cc62a22
Merge branch 'main' into fix/orchestrator-flow
Velfi May 17, 2023
3fe1471
fix stuff broken by main merge
Velfi May 17, 2023
0af1bd3
remove unused imports
Velfi May 17, 2023
7e54142
Merge branch 'main' into fix/orchestrator-flow
Velfi May 17, 2023
bc43f63
Merge branch 'main' into fix/orchestrator-flow
Velfi May 18, 2023
3141010
fix unresolved import
Velfi May 18, 2023
bacd740
fix unresolved import
Velfi May 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

#![allow(dead_code)]

use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{BoxError, Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, BoxError, Interceptor,
};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use http::header::ACCEPT;
use http::HeaderValue;
Expand All @@ -18,7 +19,7 @@ pub(crate) struct AcceptHeaderInterceptor;
impl Interceptor for AcceptHeaderInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
_cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
context
Expand Down
25 changes: 13 additions & 12 deletions aws/rust-runtime/aws-runtime/src/invocation_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, Interceptor,
};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use http::{HeaderName, HeaderValue};
use uuid::Uuid;
Expand Down Expand Up @@ -38,7 +39,7 @@ impl Default for InvocationIdInterceptor {
impl Interceptor for InvocationIdInterceptor {
fn modify_before_retry_loop(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
_cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let headers = context.request_mut().headers_mut();
Expand Down Expand Up @@ -73,31 +74,31 @@ impl InvocationId {
mod tests {
use crate::invocation_id::InvocationIdInterceptor;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::type_erasure::TypedBox;
use http::HeaderValue;

fn expect_header<'a>(
context: &'a InterceptorContext<BeforeTransmit>,
header_name: &str,
) -> &'a HeaderValue {
fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a HeaderValue {
context.request().headers().get(header_name).unwrap()
}

#[test]
fn test_id_is_generated_and_set() {
let mut context = InterceptorContext::<()>::new(TypedBox::new("doesntmatter").erase())
.into_serialization_phase();
let mut context = InterceptorContext::new(TypedBox::new("doesntmatter").erase());
context.enter_serialization_phase();
context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
let _ = context.take_input();
let mut context = context.into_before_transmit_phase();
context.enter_before_transmit_phase();

let mut config = ConfigBag::base();
let interceptor = InvocationIdInterceptor::new();
let mut ctx = Into::into(&mut context);
interceptor
.modify_before_retry_loop(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.unwrap();
interceptor
.modify_before_retry_loop(&mut ctx, &mut config)
.unwrap();

let header = expect_header(&context, "amz-sdk-invocation-id");
Expand Down
17 changes: 10 additions & 7 deletions aws/rust-runtime/aws-runtime/src/recursion_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{BoxError, Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, BoxError, Interceptor,
};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::os_shim_internal::Env;
use http::HeaderValue;
Expand Down Expand Up @@ -40,7 +41,7 @@ impl RecursionDetectionInterceptor {
impl Interceptor for RecursionDetectionInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
_cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let request = context.request_mut();
Expand Down Expand Up @@ -73,6 +74,7 @@ mod tests {
use super::*;
use aws_smithy_http::body::SdkBody;
use aws_smithy_protocol_test::{assert_ok, validate_headers};
use aws_smithy_runtime_api::client::interceptors::InterceptorContext;
use aws_smithy_runtime_api::type_erasure::TypedBox;
use aws_types::os_shim_internal::Env;
use http::HeaderValue;
Expand Down Expand Up @@ -146,15 +148,16 @@ mod tests {
request = request.header(name, value);
}
let request = request.body(SdkBody::empty()).expect("must be valid");
let mut context = InterceptorContext::<()>::new(TypedBox::new("doesntmatter").erase())
.into_serialization_phase();
let mut context = InterceptorContext::new(TypedBox::new("doesntmatter").erase());
context.enter_serialization_phase();
context.set_request(request);
let _ = context.take_input();
let mut context = context.into_before_transmit_phase();
context.enter_before_transmit_phase();
let mut config = ConfigBag::base();

let mut ctx = Into::into(&mut context);
RecursionDetectionInterceptor { env }
.modify_before_signing(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.expect("interceptor must succeed");
let mutated_request = context.request();
for name in mutated_request.headers().keys() {
Expand Down
22 changes: 10 additions & 12 deletions aws/rust-runtime/aws-runtime/src/request_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/

use aws_smithy_runtime::client::orchestrator::interceptors::{RequestAttempts, ServiceClockSkew};
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{BoxError, Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, BoxError, Interceptor,
};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_types::date_time::Format;
use aws_smithy_types::retry::RetryConfig;
Expand Down Expand Up @@ -79,7 +80,7 @@ impl RequestInfoInterceptor {
impl Interceptor for RequestInfoInterceptor {
fn modify_before_transmit(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let mut pairs = RequestPairs::new();
Expand Down Expand Up @@ -156,7 +157,6 @@ mod tests {
use crate::request_info::RequestPairs;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::client::orchestrator::interceptors::RequestAttempts;
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::type_erasure::TypedBox;
Expand All @@ -165,10 +165,7 @@ mod tests {
use http::HeaderValue;
use std::time::Duration;

fn expect_header<'a>(
context: &'a InterceptorContext<BeforeTransmit>,
header_name: &str,
) -> &'a str {
fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a str {
context
.request()
.headers()
Expand All @@ -180,8 +177,8 @@ mod tests {

#[test]
fn test_request_pairs_for_initial_attempt() {
let context = InterceptorContext::<()>::new(TypedBox::new("doesntmatter").erase());
let mut context = context.into_serialization_phase();
let mut context = InterceptorContext::new(TypedBox::new("doesntmatter").erase());
context.enter_serialization_phase();
context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());

let mut config = ConfigBag::base();
Expand All @@ -194,10 +191,11 @@ mod tests {
config.put(RequestAttempts::new());

let _ = context.take_input();
let mut context = context.into_before_transmit_phase();
context.enter_before_transmit_phase();
let interceptor = RequestInfoInterceptor::new();
let mut ctx = (&mut context).into();
interceptor
.modify_before_transmit(&mut context, &mut config)
.modify_before_transmit(&mut ctx, &mut config)
.unwrap();

assert_eq!(
Expand Down
34 changes: 19 additions & 15 deletions aws/rust-runtime/aws-runtime/src/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

use aws_http::user_agent::{ApiMetadata, AwsUserAgent};
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, Interceptor,
};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::Env;
Expand Down Expand Up @@ -73,7 +74,7 @@ fn header_values(
impl Interceptor for UserAgentInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
let api_metadata = cfg
Expand Down Expand Up @@ -113,10 +114,7 @@ mod tests {
use aws_smithy_runtime_api::type_erasure::TypedBox;
use aws_smithy_types::error::display::DisplayErrorContext;

fn expect_header<'a>(
context: &'a InterceptorContext<BeforeTransmit>,
header_name: &str,
) -> &'a str {
fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a str {
context
.request()
.headers()
Expand All @@ -126,12 +124,13 @@ mod tests {
.unwrap()
}

fn context() -> InterceptorContext<BeforeTransmit> {
let mut context = InterceptorContext::<()>::new(TypedBox::new("doesntmatter").erase())
.into_serialization_phase();
fn context() -> InterceptorContext {
let mut context = InterceptorContext::new(TypedBox::new("doesntmatter").erase());
context.enter_serialization_phase();
context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
let _ = context.take_input();
context.into_before_transmit_phase()
context.enter_before_transmit_phase();
context
}

#[test]
Expand All @@ -143,8 +142,9 @@ mod tests {
config.put(ApiMetadata::new("unused", "unused"));

let interceptor = UserAgentInterceptor::new();
let mut ctx = Into::into(&mut context);
interceptor
.modify_before_signing(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.unwrap();

let header = expect_header(&context, "user-agent");
Expand All @@ -166,8 +166,9 @@ mod tests {
config.put(api_metadata.clone());

let interceptor = UserAgentInterceptor::new();
let mut ctx = Into::into(&mut context);
interceptor
.modify_before_signing(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.unwrap();

let expected_ua = AwsUserAgent::new_from_environment(Env::real(), api_metadata);
Expand Down Expand Up @@ -195,8 +196,9 @@ mod tests {
config.put(AppName::new("my_awesome_app").unwrap());

let interceptor = UserAgentInterceptor::new();
let mut ctx = Into::into(&mut context);
interceptor
.modify_before_signing(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.unwrap();

let app_value = "app/my_awesome_app";
Expand All @@ -219,11 +221,13 @@ mod tests {
let mut config = ConfigBag::base();

let interceptor = UserAgentInterceptor::new();
let mut ctx = Into::into(&mut context);

let error = format!(
"{}",
DisplayErrorContext(
&*interceptor
.modify_before_signing(&mut context, &mut config)
.modify_before_signing(&mut ctx, &mut config)
.expect_err("it should error")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use aws_sdk_s3::Client;
use aws_smithy_client::dvr;
use aws_smithy_client::dvr::MediaType;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::interceptors::context::{Error, Input, Output};
use aws_smithy_runtime_api::client::interceptors::{
BeforeTransmitInterceptorContextMut, Interceptor,
};
use aws_smithy_runtime_api::client::orchestrator::ConfigBagAccessors;
use aws_smithy_runtime_api::client::orchestrator::RequestTime;
use aws_smithy_runtime_api::config_bag::ConfigBag;
Expand Down Expand Up @@ -59,7 +61,7 @@ struct RequestTimeResetInterceptor;
impl Interceptor for RequestTimeResetInterceptor {
fn modify_before_signing(
&self,
_context: &mut InterceptorContext<BeforeTransmit>,
_context: &mut BeforeTransmitInterceptorContextMut<'_>,
cfg: &mut ConfigBag,
) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
cfg.set_request_time(RequestTime::new(UNIX_EPOCH));
Expand All @@ -73,7 +75,7 @@ struct RequestTimeAdvanceInterceptor(Duration);
impl Interceptor for RequestTimeAdvanceInterceptor {
fn modify_before_signing(
&self,
_context: &mut InterceptorContext<BeforeTransmit>,
_context: &mut BeforeTransmitInterceptorContextMut<'_>,
cfg: &mut ConfigBag,
) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
let request_time = cfg.request_time().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions aws/sra-test/integration-tests/aws-sdk-s3/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

use aws_http::user_agent::AwsUserAgent;
use aws_runtime::invocation_id::InvocationId;
use aws_smithy_runtime_api::client::interceptors::context::phase::BeforeTransmit;
use aws_smithy_runtime_api::client::interceptors::context::{Error, Input, Output};
use aws_smithy_runtime_api::client::interceptors::{
Interceptor, InterceptorContext, InterceptorRegistrar,
BeforeTransmitInterceptorContextMut, Interceptor, InterceptorRegistrar,
};
use aws_smithy_runtime_api::client::orchestrator::{ConfigBagAccessors, RequestTime};
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct TestUserAgentInterceptor;
impl Interceptor for TestUserAgentInterceptor {
fn modify_before_signing(
&self,
context: &mut InterceptorContext<BeforeTransmit>,
context: &mut BeforeTransmitInterceptorContextMut<'_>,
_cfg: &mut ConfigBag,
) -> Result<(), aws_smithy_runtime_api::client::interceptors::BoxError> {
let headers = context.request_mut().headers_mut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class EndpointParamsInterceptorGenerator(
"HttpResponse" to orchestrator.resolve("HttpResponse"),
"Interceptor" to interceptors.resolve("Interceptor"),
"InterceptorContext" to interceptors.resolve("InterceptorContext"),
"BeforeSerializationPhase" to interceptors.resolve("context::phase::BeforeSerialization"),
"BeforeSerializationInterceptorContextRef" to interceptors.resolve("context::wrappers::BeforeSerializationInterceptorContextRef"),
"Input" to interceptors.resolve("context::Input"),
"Output" to interceptors.resolve("context::Output"),
"Error" to interceptors.resolve("context::Error"),
"InterceptorError" to interceptors.resolve("error::InterceptorError"),
"Params" to endpointTypesGenerator.paramsStruct(),
)
Expand All @@ -67,7 +70,7 @@ class EndpointParamsInterceptorGenerator(
impl #{Interceptor} for $interceptorName {
fn read_before_execution(
&self,
context: &#{InterceptorContext}<#{BeforeSerializationPhase}>,
context: &#{BeforeSerializationInterceptorContextRef}<'_, #{Input}, #{Output}, #{Error}>,
cfg: &mut #{ConfigBag},
) -> Result<(), #{BoxError}> {
let _input = context.input()
Expand Down
Loading