Unverified Commit 9a4156de authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Remove vestiges of the old TimeSource implementation & refactor (#2877)



## 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._

---------

Co-authored-by: default avatarJohn DiSanti <jdisanti@amazon.com>
parent 5d088703
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
@@ -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
+6 −11
Original line number Diff line number Diff line
@@ -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;

@@ -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);
@@ -335,7 +331,6 @@ 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;
@@ -343,7 +338,7 @@ mod test {
        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)
+7 −9
Original line number Diff line number Diff line
@@ -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};
@@ -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))
@@ -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))
+7 −16
Original line number Diff line number Diff line
@@ -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;
@@ -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()
@@ -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()
Loading