Unverified Commit 2fb21f64 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

split out interceptors (#2639)



## Motivation and Context
- split out interceptors from config bag to simplify orchestrator

## Description
- update runtime plugin trait to split out interceptors
- remove interceptor generics 
- update interceptors struct to remove locking and indirection

## Testing
- [x] ```./gradlew :aws:sra-test:assemble && (cd
aws/sra-test/integration-tests/aws-sdk-s3 && cargo test)```



----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: default avatarZelda Hessler <zhessler@amazon.com>
parent 9361aa52
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@

use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use http::{HeaderName, HeaderValue};
use uuid::Uuid;
@@ -35,10 +34,10 @@ impl Default for InvocationIdInterceptor {
    }
}

impl Interceptor<HttpRequest, HttpResponse> for InvocationIdInterceptor {
impl Interceptor for InvocationIdInterceptor {
    fn modify_before_retry_loop(
        &self,
        context: &mut InterceptorContext<HttpRequest, HttpResponse>,
        context: &mut InterceptorContext,
        _cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let headers = context.request_mut()?.headers_mut();
@@ -74,15 +73,11 @@ mod tests {
    use crate::invocation_id::InvocationIdInterceptor;
    use aws_smithy_http::body::SdkBody;
    use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
    use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
    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<HttpRequest, HttpResponse>,
        header_name: &str,
    ) -> &'a HeaderValue {
    fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a HeaderValue {
        context
            .request()
            .unwrap()
+2 −3
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
 */

use aws_smithy_runtime_api::client::interceptors::{BoxError, Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::os_shim_internal::Env;
use http::HeaderValue;
@@ -37,10 +36,10 @@ impl RecursionDetectionInterceptor {
    }
}

impl Interceptor<HttpRequest, HttpResponse> for RecursionDetectionInterceptor {
impl Interceptor for RecursionDetectionInterceptor {
    fn modify_before_signing(
        &self,
        context: &mut InterceptorContext<HttpRequest, HttpResponse>,
        context: &mut InterceptorContext,
        _cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let request = context.request_mut()?;
+3 −7
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
use aws_http::user_agent::{ApiMetadata, AwsUserAgent};
use aws_smithy_runtime_api::client::interceptors::error::BoxError;
use aws_smithy_runtime_api::client::interceptors::{Interceptor, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::Env;
@@ -70,10 +69,10 @@ fn header_values(
    ))
}

impl Interceptor<HttpRequest, HttpResponse> for UserAgentInterceptor {
impl Interceptor for UserAgentInterceptor {
    fn modify_before_signing(
        &self,
        context: &mut InterceptorContext<HttpRequest, HttpResponse>,
        context: &mut InterceptorContext,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let api_metadata = cfg
@@ -113,10 +112,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<HttpRequest, HttpResponse>,
        header_name: &str,
    ) -> &'a str {
    fn expect_header<'a>(context: &'a InterceptorContext, header_name: &str) -> &'a str {
        context
            .request()
            .unwrap()
+2 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#[macro_use]
extern crate criterion;
use aws_sdk_s3 as s3;
use aws_smithy_runtime_api::client::interceptors::Interceptors;
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_runtime_api::config_bag::ConfigBag;
use criterion::{BenchmarkId, Criterion};
@@ -94,6 +95,7 @@ async fn orchestrator(client: &s3::Client) {
        fn configure(
            &self,
            cfg: &mut ConfigBag,
            _interceptors: &mut Interceptors,
        ) -> Result<(), aws_smithy_runtime_api::client::runtime_plugin::BoxError> {
            let params_builder = s3::endpoint::Params::builder()
                .set_region(Some(self.region.clone()))
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ 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::Interceptors;
use aws_smithy_runtime_api::client::orchestrator::{ConfigBagAccessors, RequestTime};
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_runtime_api::config_bag::ConfigBag;
@@ -56,6 +57,7 @@ impl RuntimePlugin for FixupPlugin {
    fn configure(
        &self,
        cfg: &mut ConfigBag,
        _interceptors: &mut Interceptors,
    ) -> Result<(), aws_smithy_runtime_api::client::runtime_plugin::BoxError> {
        cfg.set_request_time(RequestTime::new(self.timestamp.clone()));
        cfg.put(AwsUserAgent::for_tests());
Loading