Unverified Commit 748d05cd authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

New-type the interceptor context `Input`, `Output`, and `Error` (#2872)

This PR creates new-types for `Input`, `Output`, and `Error` so that the
type system can enforce that an output isn't given to an input and vice
versa. It also removes `TypedBox` since that isn't really needed
anymore.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 911aa716
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -376,8 +376,6 @@ mod loader {
            self
        }

        // TODO(enableNewSmithyRuntimeLaunch): Remove the doc hidden from this function
        #[doc(hidden)]
        /// Don't use credentials to sign requests.
        ///
        /// Turning off signing with credentials is necessary in some cases, such as using
+4 −7
Original line number Diff line number Diff line
@@ -252,9 +252,8 @@ fn compute_hash_tree(mut hashes: Vec<Digest>) -> Digest {
#[cfg(test)]
mod account_id_autofill_tests {
    use super::*;
    use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
    use aws_smithy_runtime_api::client::interceptors::context::{Input, InterceptorContext};
    use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
    use aws_smithy_types::type_erasure::TypedBox;

    #[test]
    fn autofill_account_id() {
@@ -270,8 +269,7 @@ mod account_id_autofill_tests {

        let rc = RuntimeComponentsBuilder::for_tests().build().unwrap();
        let mut cfg = ConfigBag::base();
        let mut context =
            InterceptorContext::new(TypedBox::new(SomeInput { account_id: None }).erase());
        let mut context = InterceptorContext::new(Input::erase(SomeInput { account_id: None }));
        let mut context = BeforeSerializationInterceptorContextMut::from(&mut context);
        let interceptor = GlacierAccountIdAutofillInterceptor::<SomeInput>::new();
        interceptor
@@ -293,15 +291,14 @@ mod account_id_autofill_tests {
#[cfg(test)]
mod api_version_tests {
    use super::*;
    use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
    use aws_smithy_runtime_api::client::interceptors::context::{Input, InterceptorContext};
    use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
    use aws_smithy_types::type_erasure::TypedBox;

    #[test]
    fn api_version_interceptor() {
        let rc = RuntimeComponentsBuilder::for_tests().build().unwrap();
        let mut cfg = ConfigBag::base();
        let mut context = InterceptorContext::new(TypedBox::new("dontcare").erase());
        let mut context = InterceptorContext::new(Input::doesnt_matter());
        context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
        let mut context = BeforeTransmitInterceptorContextMut::from(&mut context);

+3 −4
Original line number Diff line number Diff line
@@ -215,12 +215,11 @@ mod tests {
    use super::*;
    use aws_smithy_http::body::SdkBody;
    use aws_smithy_runtime_api::client::interceptors::context::{
        BeforeTransmitInterceptorContextMut, InterceptorContext,
        BeforeTransmitInterceptorContextMut, Input, InterceptorContext,
    };
    use aws_smithy_runtime_api::client::interceptors::Interceptor;
    use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
    use aws_smithy_types::config_bag::{ConfigBag, Layer};
    use aws_smithy_types::type_erasure::TypeErasedBox;
    use http::HeaderValue;

    fn expect_header<'a>(
@@ -233,7 +232,7 @@ mod tests {
    #[test]
    fn default_id_generator() {
        let rc = RuntimeComponentsBuilder::for_tests().build().unwrap();
        let mut ctx = InterceptorContext::new(TypeErasedBox::doesnt_matter());
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.enter_serialization_phase();
        ctx.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
        let _ = ctx.take_input();
@@ -260,7 +259,7 @@ mod tests {
    #[test]
    fn custom_id_generator() {
        let rc = RuntimeComponentsBuilder::for_tests().build().unwrap();
        let mut ctx = InterceptorContext::new(TypeErasedBox::doesnt_matter());
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.enter_serialization_phase();
        ctx.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
        let _ = ctx.take_input();
+2 −3
Original line number Diff line number Diff line
@@ -80,9 +80,8 @@ 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::context::InterceptorContext;
    use aws_smithy_runtime_api::client::interceptors::context::{Input, InterceptorContext};
    use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
    use aws_smithy_types::type_erasure::TypeErasedBox;
    use aws_types::os_shim_internal::Env;
    use http::HeaderValue;
    use proptest::{prelude::*, proptest};
@@ -156,7 +155,7 @@ mod tests {
            request = request.header(name, value);
        }
        let request = request.body(SdkBody::empty()).expect("must be valid");
        let mut context = InterceptorContext::new(TypeErasedBox::doesnt_matter());
        let mut context = InterceptorContext::new(Input::doesnt_matter());
        context.enter_serialization_phase();
        context.set_request(request);
        let _ = context.take_input();
+9 −9
Original line number Diff line number Diff line
@@ -107,9 +107,9 @@ impl ClassifyRetry for AmzRetryAfterHeaderClassifier {
mod test {
    use super::*;
    use aws_smithy_http::body::SdkBody;
    use aws_smithy_runtime_api::client::interceptors::context::{Error, Input};
    use aws_smithy_types::error::ErrorMetadata;
    use aws_smithy_types::retry::{ErrorKind, ProvideErrorKind};
    use aws_smithy_types::type_erasure::{TypeErasedBox, TypeErasedError};
    use std::fmt;
    use std::time::Duration;

@@ -164,8 +164,8 @@ mod test {
    #[test]
    fn classify_by_error_code() {
        let policy = AwsErrorCodeClassifier::<CodedError>::new();
        let mut ctx = InterceptorContext::new(TypeErasedBox::new("doesntmatter"));
        ctx.set_output_or_error(Err(OrchestratorError::operation(TypeErasedError::new(
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.set_output_or_error(Err(OrchestratorError::operation(Error::erase(
            CodedError::new("Throttling"),
        ))));

@@ -174,8 +174,8 @@ mod test {
            Some(RetryReason::Error(ErrorKind::ThrottlingError))
        );

        let mut ctx = InterceptorContext::new(TypeErasedBox::new("doesntmatter"));
        ctx.set_output_or_error(Err(OrchestratorError::operation(TypeErasedError::new(
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.set_output_or_error(Err(OrchestratorError::operation(Error::erase(
            CodedError::new("RequestTimeout"),
        ))));
        assert_eq!(
@@ -190,9 +190,9 @@ mod test {
        let err = aws_smithy_types::Error::builder().code("SlowDown").build();
        let test_response = http::Response::new("OK").map(SdkBody::from);

        let mut ctx = InterceptorContext::new(TypeErasedBox::new("doesntmatter"));
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.set_response(test_response);
        ctx.set_output_or_error(Err(OrchestratorError::operation(TypeErasedError::new(err))));
        ctx.set_output_or_error(Err(OrchestratorError::operation(Error::erase(err))));

        assert_eq!(
            policy.classify_retry(&ctx),
@@ -208,9 +208,9 @@ mod test {
            .body("retry later")
            .unwrap()
            .map(SdkBody::from);
        let mut ctx = InterceptorContext::new(TypeErasedBox::new("doesntmatter"));
        let mut ctx = InterceptorContext::new(Input::doesnt_matter());
        ctx.set_response(res);
        ctx.set_output_or_error(Err(OrchestratorError::operation(TypeErasedError::new(
        ctx.set_output_or_error(Err(OrchestratorError::operation(Error::erase(
            UnmodeledError,
        ))));

Loading