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

WASM example on wasm-unknown-unknown now working e2e #2868

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,21 @@ message = "The `alb_health_check` module has been moved out of the `plugin` modu
references = ["smithy-rs#2865"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
author = "david-perez"

[[aws-sdk-rust]]
message = "Credential providers now share the HTTP connector used by the SDK. As a result, the `ConfigLoader::configure(...)` method has been removed. If you want to keep a separate connector for clients, use `<service>::ConfigBuilder::http_connector` when constructing the client."
references = ["aws-sdk-rust#579", "aws-sdk-rust#338"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "When creating the default credentials chain with `aws_config::from_env()`, the internal providers now use the configured sleep and time source implmentation. Prior to this fix, they always used the default implementation."
references = ["aws-sdk-rust#59"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[aws-sdk-rust]]
message = "ProviderConfig::with_http_connector now accepts an `HttpConnector` instead of a `DynConnector`. This allows HTTP connectors to be configured which correctly respect timeouts."
references = ["aws-sdk-rust#579", "aws-sdk-rust#338"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ serde_json = "1"

aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"] }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["test-util"] }

# used for a usage example
hyper-rustls = { version = "0.24", features = ["webpki-tokio", "http2", "http1"] }
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-config/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,9 @@ mod tests {
async fn profile_name_override() {
let fs = Fs::from_slice(&[("test_config", "[profile custom]\nsdk_ua_app_id = correct")]);
let conf = crate::from_env()
.configure(
ProviderConfig::empty()
.with_fs(fs)
.with_sleep(InstantSleep)
.with_http_connector(no_traffic_connector()),
)
.fs(fs)
.sleep_impl(InstantSleep)
.http_connector(no_traffic_connector())
.profile_name("custom")
.profile_files(
ProfileFiles::builder()
Expand Down
16 changes: 5 additions & 11 deletions aws/rust-runtime/aws-config/src/default_provider/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl Builder {
#[cfg(test)]
mod test {
use aws_credential_types::provider::ProvideCredentials;
use aws_smithy_async::time::{SharedTimeSource, StaticTimeSource};

use crate::default_provider::credentials::DefaultCredentialsChain;

Expand Down Expand Up @@ -279,21 +280,15 @@ mod test {
make_test!(imds_no_iam_role);
make_test!(imds_default_chain_error);
make_test!(imds_default_chain_success, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
config.with_time_source(StaticTimeSource::new(std::time::UNIX_EPOCH))
});
make_test!(imds_assume_role);
make_test!(imds_config_with_no_creds, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
config.with_time_source(StaticTimeSource::new(std::time::UNIX_EPOCH))
});
make_test!(imds_disabled);
make_test!(imds_default_chain_retries, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
config.with_time_source(StaticTimeSource::new(std::time::UNIX_EPOCH))
});
make_test!(ecs_assume_role);
make_test!(ecs_credentials);
Expand Down Expand Up @@ -335,15 +330,14 @@ mod test {
async fn no_providers_configured_err() {
use crate::provider_config::ProviderConfig;
use aws_credential_types::provider::error::CredentialsError;
use aws_credential_types::time_source::TimeSource;
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_client::erase::boxclone::BoxCloneService;
use aws_smithy_client::never::NeverConnected;

tokio::time::pause();
let conf = ProviderConfig::no_configuration()
.with_tcp_connector(BoxCloneService::new(NeverConnected::new()))
.with_time_source(TimeSource::default())
.with_time_source(SharedTimeSource::default())
.with_sleep(TokioSleep::new());
let provider = DefaultCredentialsChain::builder()
.configure(conf)
Expand Down
16 changes: 7 additions & 9 deletions aws/rust-runtime/aws-config/src/imds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ impl<T, E> ClassifyRetry<SdkSuccess<T>, SdkError<E>> for ImdsResponseRetryClassi
pub(crate) mod test {
use crate::imds::client::{Client, EndpointMode, ImdsResponseRetryClassifier};
use crate::provider_config::ProviderConfig;
use aws_credential_types::time_source::{TestingTimeSource, TimeSource};
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_async::test_util::instant_time_and_sleep;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::test_connection::{capture_request, TestConnection};
use aws_smithy_client::{SdkError, SdkSuccess};
Expand Down Expand Up @@ -700,14 +700,13 @@ pub(crate) mod test {
imds_response(r#"test-imds-output2"#),
),
]);
let mut time_source = TestingTimeSource::new(UNIX_EPOCH);
tokio::time::pause();
let (time_source, sleep) = instant_time_and_sleep(UNIX_EPOCH);
let client = super::Client::builder()
.configure(
&ProviderConfig::no_configuration()
.with_http_connector(DynConnector::new(connection.clone()))
.with_time_source(TimeSource::testing(&time_source))
.with_sleep(TokioSleep::new()),
.with_time_source(time_source.clone())
.with_sleep(sleep),
)
.endpoint_mode(EndpointMode::IpV6)
.token_ttl(Duration::from_secs(600))
Expand Down Expand Up @@ -752,14 +751,13 @@ pub(crate) mod test {
imds_response(r#"test-imds-output3"#),
),
]);
tokio::time::pause();
let mut time_source = TestingTimeSource::new(UNIX_EPOCH);
let (time_source, sleep) = instant_time_and_sleep(UNIX_EPOCH);
let client = super::Client::builder()
.configure(
&ProviderConfig::no_configuration()
.with_sleep(TokioSleep::new())
.with_sleep(sleep)
.with_http_connector(DynConnector::new(connection.clone()))
.with_time_source(TimeSource::testing(&time_source)),
.with_time_source(time_source.clone()),
)
.endpoint_mode(EndpointMode::IpV6)
.token_ttl(Duration::from_secs(600))
Expand Down
23 changes: 7 additions & 16 deletions aws/rust-runtime/aws-config/src/imds/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ mod test {
};
use crate::provider_config::ProviderConfig;
use aws_credential_types::provider::ProvideCredentials;
use aws_credential_types::time_source::{TestingTimeSource, TimeSource};
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_async::test_util::instant_time_and_sleep;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::test_connection::TestConnection;
use tracing_test::traced_test;
Expand Down Expand Up @@ -369,16 +368,12 @@ mod test {
// set to 2021-09-21T04:16:50Z that makes returned credentials' expiry (2021-09-21T04:16:53Z)
// not stale
let time_of_request_to_fetch_credentials = UNIX_EPOCH + Duration::from_secs(1632197810);
let time_source = TimeSource::testing(&TestingTimeSource::new(
time_of_request_to_fetch_credentials,
));

tokio::time::pause();
let (time_source, sleep) = instant_time_and_sleep(time_of_request_to_fetch_credentials);

let provider_config = ProviderConfig::no_configuration()
.with_http_connector(DynConnector::new(connection.clone()))
.with_time_source(time_source)
.with_sleep(TokioSleep::new());
.with_sleep(sleep)
.with_time_source(time_source);
let client = crate::imds::Client::builder()
.configure(&provider_config)
.build()
Expand Down Expand Up @@ -419,16 +414,12 @@ mod test {

// set to 2021-09-21T17:41:25Z that renders fetched credentials already expired (2021-09-21T04:16:53Z)
let time_of_request_to_fetch_credentials = UNIX_EPOCH + Duration::from_secs(1632246085);
let time_source = TimeSource::testing(&TestingTimeSource::new(
time_of_request_to_fetch_credentials,
));

tokio::time::pause();
let (time_source, sleep) = instant_time_and_sleep(time_of_request_to_fetch_credentials);

let provider_config = ProviderConfig::no_configuration()
.with_http_connector(DynConnector::new(connection.clone()))
.with_time_source(time_source)
.with_sleep(TokioSleep::new());
.with_sleep(sleep)
.with_time_source(time_source);
let client = crate::imds::Client::builder()
.configure(&provider_config)
.build()
Expand Down
115 changes: 49 additions & 66 deletions aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ mod loader {
use aws_smithy_types::timeout::TimeoutConfig;
use aws_types::app_name::AppName;
use aws_types::docs_for;
use aws_types::os_shim_internal::{Env, Fs};
use aws_types::SdkConfig;

use crate::connector::default_connector;
Expand Down Expand Up @@ -198,13 +199,14 @@ mod loader {
retry_config: Option<RetryConfig>,
sleep: Option<SharedAsyncSleep>,
timeout_config: Option<TimeoutConfig>,
provider_config: Option<ProviderConfig>,
http_connector: Option<HttpConnector>,
profile_name_override: Option<String>,
profile_files_override: Option<ProfileFiles>,
use_fips: Option<bool>,
use_dual_stack: Option<bool>,
time_source: Option<SharedTimeSource>,
fs: Option<Fs>,
env: Option<Env>,
}

impl ConfigLoader {
Expand Down Expand Up @@ -513,30 +515,6 @@ mod loader {
self
}

/// Set configuration for all sub-loaders (credentials, region etc.)
///
/// Update the `ProviderConfig` used for all nested loaders. This can be used to override
/// the HTTPs connector used by providers or to stub in an in memory `Env` or `Fs` for testing.
///
/// # Examples
/// ```no_run
/// # #[cfg(feature = "hyper-client")]
/// # async fn create_config() {
/// use aws_config::provider_config::ProviderConfig;
/// let custom_https_connector = hyper_rustls::HttpsConnectorBuilder::new()
/// .with_webpki_roots()
/// .https_only()
/// .enable_http1()
/// .build();
/// let provider_config = ProviderConfig::default().with_tcp_connector(custom_https_connector);
/// let shared_config = aws_config::from_env().configure(provider_config).load().await;
/// # }
/// ```
pub fn configure(mut self, provider_config: ProviderConfig) -> Self {
self.provider_config = Some(provider_config);
self
}

/// Load the default configuration chain
///
/// If fields have been overridden during builder construction, the override values will be used.
Expand All @@ -547,10 +525,30 @@ mod loader {
/// This means that if you provide a region provider that does not return a region, no region will
/// be set in the resulting [`SdkConfig`](aws_types::SdkConfig)
pub async fn load(self) -> SdkConfig {
let conf = self
.provider_config
.unwrap_or_default()
.with_profile_config(self.profile_files_override, self.profile_name_override);
let sleep_impl = if self.sleep.is_some() {
self.sleep
} else {
if default_async_sleep().is_none() {
tracing::warn!(
"An implementation of AsyncSleep was requested by calling default_async_sleep \
but no default was set.
This happened when ConfigLoader::load was called during Config construction. \
You can fix this by setting a sleep_impl on the ConfigLoader before calling \
load or by enabling the rt-tokio feature"
);
}
default_async_sleep()
};
let http_connector = self
.http_connector
.unwrap_or_else(|| HttpConnector::ConnectorFn(Arc::new(default_connector)));

let ts = self.time_source.unwrap_or_default();
let conf = ProviderConfig::init(ts.clone(), sleep_impl.clone())
.with_profile_config(self.profile_files_override, self.profile_name_override)
.with_fs(self.fs.unwrap_or_default())
.with_http_connector(http_connector.clone())
.with_env(self.env.unwrap_or_default());
let region = if let Some(provider) = self.region {
provider.region().await
} else {
Expand Down Expand Up @@ -579,21 +577,6 @@ mod loader {
.await
};

let sleep_impl = if self.sleep.is_some() {
self.sleep
} else {
if default_async_sleep().is_none() {
tracing::warn!(
"An implementation of AsyncSleep was requested by calling default_async_sleep \
but no default was set.
This happened when ConfigLoader::load was called during Config construction. \
You can fix this by setting a sleep_impl on the ConfigLoader before calling \
load or by enabling the rt-tokio feature"
);
}
default_async_sleep()
};

let timeout_config = if let Some(timeout_config) = self.timeout_config {
timeout_config
} else {
Expand All @@ -603,10 +586,6 @@ mod loader {
.await
};

let http_connector = self
.http_connector
.unwrap_or_else(|| HttpConnector::ConnectorFn(Arc::new(default_connector)));

let credentials_provider = match self.credentials_provider {
CredentialsProviderOption::Set(provider) => Some(provider),
CredentialsProviderOption::NotSet => {
Expand All @@ -620,9 +599,8 @@ mod loader {

let credentials_cache = if credentials_provider.is_some() {
Some(self.credentials_cache.unwrap_or_else(|| {
let mut builder = CredentialsCache::lazy_builder().time_source(
aws_credential_types::time_source::TimeSource::shared(conf.time_source()),
);
let mut builder =
CredentialsCache::lazy_builder().time_source(conf.time_source());
builder.set_sleep(conf.sleep());
builder.into_credentials_cache()
}))
Expand All @@ -642,8 +620,6 @@ mod loader {
use_dual_stack_provider(&conf).await
};

let ts = self.time_source.unwrap_or_default();

let mut builder = SdkConfig::builder()
.region(region)
.retry_config(retry_config)
Expand All @@ -662,6 +638,19 @@ mod loader {
}
}

#[cfg(test)]
impl ConfigLoader {
pub(crate) fn env(mut self, env: Env) -> Self {
self.env = Some(env);
self
}

pub(crate) fn fs(mut self, fs: Fs) -> Self {
self.fs = Some(fs);
self
}
}

#[cfg(test)]
mod test {
use aws_credential_types::provider::ProvideCredentials;
Expand All @@ -673,7 +662,6 @@ mod loader {
use tracing_test::traced_test;

use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;
use crate::test_case::{no_traffic_connector, InstantSleep};
use crate::{from_env, ConfigLoader};

Expand All @@ -689,13 +677,10 @@ mod loader {
let fs =
Fs::from_slice(&[("test_config", "[profile custom]\nsdk-ua-app-id = correct")]);
let loader = from_env()
.configure(
ProviderConfig::empty()
.with_sleep(TokioSleep::new())
.with_env(env)
.with_fs(fs)
.with_http_connector(DynConnector::new(NeverConnector::new())),
)
.sleep_impl(TokioSleep::new())
.http_connector(DynConnector::new(NeverConnector::new()))
.env(env)
.fs(fs)
.profile_name("custom")
.profile_files(
ProfileFiles::builder()
Expand Down Expand Up @@ -735,11 +720,9 @@ mod loader {
}

fn base_conf() -> ConfigLoader {
from_env().configure(
ProviderConfig::empty()
.with_sleep(InstantSleep)
.with_http_connector(no_traffic_connector()),
)
from_env()
.sleep_impl(InstantSleep)
.http_connector(no_traffic_connector())
}

#[tokio::test]
Expand Down
Loading