Commit e821df60 authored by AWS SDK Rust Bot's avatar AWS SDK Rust Bot
Browse files

[smithy-rs] Rollup of 3 commits



Includes commits:
  af8474aa Ignore more tests (#3057)
  3b6f8867 New-type all the orchestrator futures (#3055)
  5a2dbd43 fix various small issues (#3056)

Co-authored-by: default avatarJohn DiSanti <jdisanti@amazon.com>
Co-authored-by: default avatarRussell Cohen <rcoh@amazon.com>
Co-authored-by: default avatarZelda Hessler <zhessler@amazon.com>
parent 4dfc7e90
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::orchestrator::operation::Operation;
use aws_smithy_runtime::client::retries::strategy::StandardRetryStrategy;
use aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams;
use aws_smithy_runtime_api::client::endpoint::{EndpointResolver, EndpointResolverParams};
use aws_smithy_runtime_api::client::endpoint::{
    EndpointFuture, EndpointResolver, EndpointResolverParams,
};
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
use aws_smithy_runtime_api::client::orchestrator::{Future, OrchestratorError, SensitiveOutput};
use aws_smithy_runtime_api::client::orchestrator::{OrchestratorError, SensitiveOutput};
use aws_smithy_runtime_api::client::retries::classifiers::{
    ClassifyRetry, RetryAction, SharedRetryClassifier,
};
@@ -522,15 +524,15 @@ struct ImdsEndpointResolver {
}

impl EndpointResolver for ImdsEndpointResolver {
    fn resolve_endpoint(&self, _: &EndpointResolverParams) -> Future<Endpoint> {
    fn resolve_endpoint(&self, _: &EndpointResolverParams) -> EndpointFuture {
        let this = self.clone();
        Future::new(Box::pin(async move {
        EndpointFuture::new(async move {
            this.endpoint_source
                .endpoint(this.mode_override)
                .await
                .map(|uri| Endpoint::builder().url(uri.to_string()).build())
                .map_err(|err| err.into())
        }))
        })
    }
}

+5 −7
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ use aws_smithy_runtime_api::client::auth::{
    AuthScheme, AuthSchemeEndpointConfig, AuthSchemeId, Signer,
};
use aws_smithy_runtime_api::client::identity::{
    Identity, IdentityResolver, SharedIdentityResolver,
};
use aws_smithy_runtime_api::client::orchestrator::{
    Future, HttpRequest, HttpResponse, OrchestratorError,
    Identity, IdentityFuture, IdentityResolver, SharedIdentityResolver,
};
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse, OrchestratorError};
use aws_smithy_runtime_api::client::runtime_components::{
    GetIdentityResolver, RuntimeComponents, RuntimeComponentsBuilder,
};
@@ -194,9 +192,9 @@ fn parse_token_response(response: &HttpResponse, now: SystemTime) -> Result<Toke
}

impl IdentityResolver for TokenResolver {
    fn resolve_identity(&self, _config_bag: &ConfigBag) -> Future<Identity> {
    fn resolve_identity(&self, _config_bag: &ConfigBag) -> IdentityFuture {
        let this = self.clone();
        Future::new(Box::pin(async move {
        IdentityFuture::new(async move {
            let preloaded_token = this
                .inner
                .cache
@@ -217,7 +215,7 @@ impl IdentityResolver for TokenResolver {

            let expiry = token.expiry;
            Ok(Identity::new(token, Some(expiry)))
        }))
        })
    }
}

+5 −7
Original line number Diff line number Diff line
@@ -6,9 +6,7 @@
/// Credentials-based identity support.
pub mod credentials {
    use aws_credential_types::cache::SharedCredentialsCache;
    use aws_smithy_runtime_api::box_error::BoxError;
    use aws_smithy_runtime_api::client::identity::{Identity, IdentityResolver};
    use aws_smithy_runtime_api::client::orchestrator::Future;
    use aws_smithy_runtime_api::client::identity::{Identity, IdentityFuture, IdentityResolver};
    use aws_smithy_types::config_bag::ConfigBag;

    /// Smithy identity resolver for AWS credentials.
@@ -25,13 +23,13 @@ pub mod credentials {
    }

    impl IdentityResolver for CredentialsIdentityResolver {
        fn resolve_identity(&self, _config_bag: &ConfigBag) -> Future<Identity> {
        fn resolve_identity(&self, _config_bag: &ConfigBag) -> IdentityFuture {
            let cache = self.credentials_cache.clone();
            Future::new(Box::pin(async move {
            IdentityFuture::new(async move {
                let credentials = cache.as_ref().provide_cached_credentials().await?;
                let expiration = credentials.expiry();
                Result::<_, BoxError>::Ok(Identity::new(credentials, expiration))
            }))
                Ok(Identity::new(credentials, expiration))
            })
        }
    }
}
+62 −0
Original line number Diff line number Diff line
@@ -3,6 +3,68 @@
 * SPDX-License-Identifier: Apache-2.0
 */

macro_rules! new_type_future {
    (
        doc = $type_docs:literal,
        pub struct $future_name:ident<$output:ty, $err:ty>,
    ) => {
        pin_project_lite::pin_project! {
            #[allow(clippy::type_complexity)]
            #[doc = $type_docs]
            pub struct $future_name {
                #[pin]
                inner: aws_smithy_async::future::now_or_later::NowOrLater<
                    Result<$output, $err>,
                    aws_smithy_async::future::BoxFuture<$output, $err>
                >,
            }
        }

        impl $future_name {
            #[doc = concat!("Create a new `", stringify!($future_name), "` with the given future.")]
            pub fn new<F>(future: F) -> Self
            where
                F: std::future::Future<Output = Result<$output, $err>> + Send + 'static,
            {
                Self {
                    inner: aws_smithy_async::future::now_or_later::NowOrLater::new(Box::pin(future)),
                }
            }

            #[doc = concat!("
            Create a new `", stringify!($future_name), "` with the given boxed future.

            Use this if you already have a boxed future to avoid double boxing it.
            ")]
            pub fn new_boxed(
                future: std::pin::Pin<
                    Box<dyn std::future::Future<Output = Result<$output, $err>> + Send>,
                >,
            ) -> Self {
                Self {
                    inner: aws_smithy_async::future::now_or_later::NowOrLater::new(future),
                }
            }

            #[doc = concat!("Create a `", stringify!($future_name), "` that is immediately ready with the given result.")]
            pub fn ready(result: Result<$output, $err>) -> Self {
                Self {
                    inner: aws_smithy_async::future::now_or_later::NowOrLater::ready(result),
                }
            }
        }

        impl std::future::Future for $future_name {
            type Output = Result<$output, $err>;

            fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
                let this = self.project();
                this.inner.poll(cx)
            }
        }
    };
}

pub mod dns;

pub mod endpoint;
+8 −3
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@

//! APIs needed to configure endpoint resolution for clients.

use crate::client::orchestrator::Future;
use crate::box_error::BoxError;
use crate::impl_shared_conversions;
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use aws_smithy_types::endpoint::Endpoint;
@@ -13,6 +13,11 @@ use aws_smithy_types::type_erasure::TypeErasedBox;
use std::fmt;
use std::sync::Arc;

new_type_future! {
    doc = "Future for [`EndpointResolver::resolve_endpoint`].",
    pub struct EndpointFuture<Endpoint, BoxError>,
}

/// Parameters originating from the Smithy endpoint ruleset required for endpoint resolution.
///
/// The actual endpoint parameters are code generated from the Smithy model, and thus,
@@ -40,7 +45,7 @@ impl Storable for EndpointResolverParams {
/// Configurable endpoint resolver implementation.
pub trait EndpointResolver: Send + Sync + fmt::Debug {
    /// Asynchronously resolves an endpoint to use from the given endpoint parameters.
    fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint>;
    fn resolve_endpoint(&self, params: &EndpointResolverParams) -> EndpointFuture;
}

/// Shared endpoint resolver.
@@ -57,7 +62,7 @@ impl SharedEndpointResolver {
}

impl EndpointResolver for SharedEndpointResolver {
    fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint> {
    fn resolve_endpoint(&self, params: &EndpointResolverParams) -> EndpointFuture {
        self.0.resolve_endpoint(params)
    }
}
Loading