Skip to content

Commit

Permalink
Remove vestiges of the old TimeSource implementation & refactor (#2877)
Browse files Browse the repository at this point in the history
## Motivation and Context
When `TimeSource` was created, we didn't carefully track down all the
places and left a bit of existing implementation to limit the scope of
the change.
## Description
This removes the public (doc hidden) Testing code from
aws-credential-types and our other test time sources instead.


## Testing
- IT/UT

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
rcoh authored Jul 26, 2023
1 parent 5d08870 commit 6ccbb2f
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 238 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,15 @@ x-amzn-errortype: InvalidRequestException
references = ["smithy-rs#2866"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server" }
author = "david-perez"

[[aws-sdk-rust]]
message = """The `doc(hidden)` `time_source` in `aws-credential-types` was removed. Use `aws_smithy_async::time` instead."""
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"
references = ["smithy-rs#2877"]

[[aws-sdk-rust]]
message = """The `doc(hidden)` `with_env` in `ProviderConfig` was removed."""
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "rcoh"
references = ["smithy-rs#2877"]
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 @@ -66,6 +66,7 @@ aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", fe

# used for a usage example
hyper-rustls = { version = "0.24", features = ["webpki-tokio", "http2", "http1"] }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["test-util"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
17 changes: 6 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,8 @@ impl Builder {
#[cfg(test)]
mod test {
use aws_credential_types::provider::ProvideCredentials;
use aws_smithy_async::time::StaticTimeSource;
use std::time::UNIX_EPOCH;

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

Expand Down Expand Up @@ -279,21 +281,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(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(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(UNIX_EPOCH))
});
make_test!(ecs_assume_role);
make_test!(ecs_credentials);
Expand Down Expand Up @@ -335,15 +331,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(StaticTimeSource::new(UNIX_EPOCH))
.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
5 changes: 2 additions & 3 deletions aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,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 Down
10 changes: 6 additions & 4 deletions aws/rust-runtime/aws-config/src/provider_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

//! Configuration Options for Credential Providers

use aws_credential_types::time_source::TimeSource;
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
use aws_smithy_async::time::SharedTimeSource;
use aws_smithy_client::erase::DynConnector;
Expand Down Expand Up @@ -282,7 +281,7 @@ impl ProviderConfig {
}
}

#[doc(hidden)]
#[cfg(test)]
pub fn with_env(self, env: Env) -> Self {
ProviderConfig {
parsed_profile: Default::default(),
Expand All @@ -291,8 +290,11 @@ impl ProviderConfig {
}
}

#[doc(hidden)]
pub fn with_time_source(self, time_source: TimeSource) -> Self {
/// Override the time source for this configuration
pub fn with_time_source(
self,
time_source: impl aws_smithy_async::time::TimeSource + 'static,
) -> Self {
ProviderConfig {
time_source: SharedTimeSource::new(time_source),
..self
Expand Down
15 changes: 7 additions & 8 deletions aws/rust-runtime/aws-config/src/sts/assume_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ mod test {
use crate::sts::AssumeRoleProvider;
use aws_credential_types::credential_fn::provide_credentials_fn;
use aws_credential_types::provider::ProvideCredentials;
use aws_credential_types::time_source::{TestingTimeSource, TimeSource};
use aws_credential_types::Credentials;
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_async::test_util::instant_time_and_sleep;
use aws_smithy_async::time::StaticTimeSource;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::test_connection::{capture_request, TestConnection};
use aws_smithy_http::body::SdkBody;
Expand All @@ -305,9 +306,9 @@ mod test {
let (server, request) = capture_request(None);
let provider_conf = ProviderConfig::empty()
.with_sleep(TokioSleep::new())
.with_time_source(TimeSource::testing(&TestingTimeSource::new(
.with_time_source(StaticTimeSource::new(
UNIX_EPOCH + Duration::from_secs(1234567890 - 120),
)))
))
.with_http_connector(DynConnector::new(server));
let provider = AssumeRoleProvider::builder("myrole")
.configure(&provider_conf)
Expand Down Expand Up @@ -335,13 +336,13 @@ mod test {
)).unwrap()),
]);

let mut testing_time_source = TestingTimeSource::new(
let (testing_time_source, sleep) = instant_time_and_sleep(
UNIX_EPOCH + Duration::from_secs(1234567890 - 120), // 1234567890 since UNIX_EPOCH is 2009-02-13T23:31:30Z
);

let provider_conf = ProviderConfig::empty()
.with_sleep(TokioSleep::new())
.with_time_source(TimeSource::testing(&testing_time_source))
.with_sleep(sleep)
.with_time_source(testing_time_source.clone())
.with_http_connector(DynConnector::new(conn));
let credentials_list = std::sync::Arc::new(std::sync::Mutex::new(vec![
Credentials::new(
Expand Down Expand Up @@ -371,8 +372,6 @@ mod test {
}
}));

tokio::time::pause();

let creds_first = provider
.provide_credentials()
.await
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-credential-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tracing = "0.1"
zeroize = "1"

[dev-dependencies]
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async", features = ["rt-tokio"] }
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async", features = ["rt-tokio", "test-util"] }

# used to test compatibility
async-trait = "0.1.51"
Expand Down
Loading

0 comments on commit 6ccbb2f

Please sign in to comment.