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

Split runtime components out of config in the orchestrator impl (#2832)

This PR moves all the "runtime components", pieces that are core to the
operation of the orchestrator, into a separate `RuntimeComponents` type
for the orchestrator to reference directly.

The reason for this is so that these core components cannot be changed
by interceptors while the orchestrator is executing a request.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 3ee63a84
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ tracing = "0.1"
aws-credential-types = { path = "../aws-credential-types", features = ["test-util"] }
aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client", features = ["test-util"] }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http", features = ["rt-tokio"] }
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["test-util"] }
tempfile = "3.6.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async", features = ["test-util"] }
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
use aws_smithy_runtime_api::client::interceptors::Interceptor;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::ConfigBag;
use http::header::ACCEPT;
use http::HeaderValue;
@@ -20,6 +21,7 @@ impl Interceptor for AcceptHeaderInterceptor {
    fn modify_before_signing(
        &self,
        context: &mut BeforeTransmitInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        _cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        context
+11 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{
};
use aws_smithy_runtime_api::client::interceptors::Interceptor;
use aws_smithy_runtime_api::client::orchestrator::LoadedRequestBody;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::ConfigBag;
use bytes::Bytes;
use http::header::{HeaderName, HeaderValue};
@@ -71,6 +72,7 @@ impl<I: GlacierAccountId + Send + Sync + 'static> Interceptor
    fn modify_before_serialization(
        &self,
        context: &mut BeforeSerializationInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        _cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let erased_input = context.input_mut();
@@ -99,6 +101,7 @@ impl Interceptor for GlacierApiVersionInterceptor {
    fn modify_before_signing(
        &self,
        context: &mut BeforeTransmitInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        _cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        context.request_mut().headers_mut().insert(
@@ -117,6 +120,7 @@ impl Interceptor for GlacierTreeHashHeaderInterceptor {
    fn modify_before_serialization(
        &self,
        _context: &mut BeforeSerializationInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        // Request the request body to be loaded into memory immediately after serialization
@@ -129,6 +133,7 @@ impl Interceptor for GlacierTreeHashHeaderInterceptor {
    fn modify_before_retry_loop(
        &self,
        context: &mut BeforeTransmitInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let maybe_loaded_body = cfg.load::<LoadedRequestBody>();
@@ -237,6 +242,7 @@ fn compute_hash_tree(mut hashes: Vec<Digest>) -> Digest {
mod account_id_autofill_tests {
    use super::*;
    use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
    use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
    use aws_smithy_types::type_erasure::TypedBox;

    #[test]
@@ -251,13 +257,14 @@ 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 = BeforeSerializationInterceptorContextMut::from(&mut context);
        let interceptor = GlacierAccountIdAutofillInterceptor::<SomeInput>::new();
        interceptor
            .modify_before_serialization(&mut context, &mut cfg)
            .modify_before_serialization(&mut context, &rc, &mut cfg)
            .expect("success");
        assert_eq!(
            DEFAULT_ACCOUNT_ID,
@@ -276,10 +283,12 @@ mod account_id_autofill_tests {
mod api_version_tests {
    use super::*;
    use aws_smithy_runtime_api::client::interceptors::context::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());
        context.set_request(http::Request::builder().body(SdkBody::empty()).unwrap());
@@ -287,7 +296,7 @@ mod api_version_tests {

        let interceptor = GlacierApiVersionInterceptor::new("some-version");
        interceptor
            .modify_before_signing(&mut context, &mut cfg)
            .modify_before_signing(&mut context, &rc, &mut cfg)
            .expect("success");

        assert_eq!(
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{
    BeforeSerializationInterceptorContextRef, BeforeTransmitInterceptorContextMut, Input,
};
use aws_smithy_runtime_api::client::interceptors::Interceptor;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
use http::HeaderValue;
use http_body::Body;
@@ -81,6 +82,7 @@ where
    fn read_before_serialization(
        &self,
        context: &BeforeSerializationInterceptorContextRef<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let checksum_algorithm = (self.algorithm_provider)(context.input())?;
@@ -98,6 +100,7 @@ where
    fn modify_before_retry_loop(
        &self,
        context: &mut BeforeTransmitInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let state = cfg
+3 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{
    BeforeDeserializationInterceptorContextMut, BeforeSerializationInterceptorContextRef, Input,
};
use aws_smithy_runtime_api::client::interceptors::Interceptor;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
use http::HeaderValue;
use std::{fmt, mem};
@@ -58,6 +59,7 @@ where
    fn read_before_serialization(
        &self,
        context: &BeforeSerializationInterceptorContextRef<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let validation_enabled = (self.validation_enabled)(context.input());
@@ -72,6 +74,7 @@ where
    fn modify_before_deserialization(
        &self,
        context: &mut BeforeDeserializationInterceptorContextMut<'_>,
        _runtime_components: &RuntimeComponents,
        cfg: &mut ConfigBag,
    ) -> Result<(), BoxError> {
        let state = cfg
Loading