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

Rename behavior versions and associated functions (#3204)

The previous names are just too verbose. This PR shortens them and tries
to make things clearer.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent c830caa2
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -68,15 +68,15 @@ meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = """Clients now require a `BehaviorMajorVersion` to be provided. For must customers, `latest` is the best choice. This will be enabled automatically if you enable the `behavior-version-latest` cargo feature on `aws-config` or on an SDK crate. For customers that wish to pin to a specific behavior major version, it can be set in `aws-config` or when constructing the service client.
message = """Clients now require a `BehaviorVersion` to be provided. For must customers, `latest` is the best choice. This will be enabled automatically if you enable the `behavior-version-latest` cargo feature on `aws-config` or on an SDK crate. For customers that wish to pin to a specific behavior major version, it can be set in `aws-config` or when constructing the service client.

```rust
async fn example() {
    // with aws-config
    let conf = aws_config::from_env_with_version(aws_config::BehaviorMajorVersion::v2023_11_09());
    let conf = aws_config::defaults(aws_config::BehaviorVersion::v2023_11_09());

    // when creating a client
    let client = my_service::Client::from_conf(my_service::Config::builder().behavior_major_version(..).<other params>.build());
    let client = my_service::Client::from_conf(my_service::Config::builder().behavior_version(..).<other params>.build());
}
```"""
references = ["smithy-rs#3151"]
@@ -84,12 +84,12 @@ author = "rcoh"
meta = { "breaking" = true, "tada" = false, "bug" = false }

[[smithy-rs]]
message = """Clients now require a `BehaviorMajorVersion` to be provided. For must customers, `latest` is the best choice. This will be enabled automatically if you enable the `behavior-version-latest` cargo feature on `aws-config` or on an SDK crate. For customers that wish to pin to a specific behavior major version, it can be set in `aws-config` or when constructing the service client.
message = """Clients now require a `BehaviorVersion` to be provided. For must customers, `latest` is the best choice. This will be enabled automatically if you enable the `behavior-version-latest` cargo feature on `aws-config` or on an SDK crate. For customers that wish to pin to a specific behavior major version, it can be set in `aws-config` or when constructing the service client.

```rust
async fn example() {
    // when creating a client
    let client = my_service::Client::from_conf(my_service::Config::builder().behavior_major_version(..).<other params>.build());
    let client = my_service::Client::from_conf(my_service::Config::builder().behavior_version(..).<other params>.build());
}
```"""
references = ["smithy-rs#3151"]
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ allowed_external_types = [
   "aws_smithy_runtime_api::client::http::SharedHttpClient",
   "aws_smithy_runtime_api::client::identity::ResolveCachedIdentity",
   "aws_smithy_runtime_api::client::identity::ResolveIdentity",
   "aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion",
   "aws_smithy_runtime_api::client::behavior_version::BehaviorVersion",
   "aws_smithy_runtime_api::client::orchestrator::HttpResponse",
   "aws_smithy_runtime_api::client::result::SdkError",
   "aws_smithy_types::body::SdkBody",
+2 −2
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ mod tests {
    use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
    use crate::provider_config::ProviderConfig;
    use crate::test_case::{no_traffic_client, InstantSleep};
    use aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion;
    use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
    use aws_types::os_shim_internal::{Env, Fs};

    #[tokio::test]
@@ -118,7 +118,7 @@ mod tests {
    #[tokio::test]
    async fn profile_name_override() {
        let fs = Fs::from_slice(&[("test_config", "[profile custom]\nsdk_ua_app_id = correct")]);
        let conf = crate::from_env_with_version(BehaviorMajorVersion::latest())
        let conf = crate::defaults(BehaviorVersion::latest())
            .sleep_impl(InstantSleep)
            .fs(fs)
            .http_client(no_traffic_client())
+43 −46
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
//!
//! Load default SDK configuration:
//! ```no_run
//! use aws_config::BehaviorMajorVersion;
//! use aws_config::BehaviorVersion;
//! mod aws_sdk_dynamodb {
//! #   pub struct Client;
//! #   impl Client {
@@ -34,7 +34,7 @@
//! #   }
//! # }
//! # async fn docs() {
//! let config = aws_config::load_from_env_with_version(BehaviorMajorVersion::v2023_11_09()).await;
//! let config = aws_config::load_defaults(BehaviorVersion::v2023_11_09()).await;
//! let client = aws_sdk_dynamodb::Client::new(&config);
//! # }
//! ```
@@ -87,7 +87,7 @@
//! # fn custom_provider(base: &SdkConfig) -> impl ProvideCredentials {
//! #   base.credentials_provider().unwrap().clone()
//! # }
//! let sdk_config = aws_config::load_from_env_with_version(aws_config::BehaviorMajorVersion::latest()).await;
//! let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
//! let custom_credentials_provider = custom_provider(&sdk_config);
//! let dynamo_config = aws_sdk_dynamodb::config::Builder::from(&sdk_config)
//!   .credentials_provider(custom_credentials_provider)
@@ -97,7 +97,7 @@
//! ```

pub use aws_smithy_http::endpoint;
pub use aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion;
pub use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
// Re-export types from aws-types
pub use aws_types::{
    app_name::{AppName, InvalidAppName},
@@ -140,9 +140,9 @@ pub mod sts;
pub mod timeout;
pub mod web_identity_token;

/// Create an environment loader for AWS Configuration
/// Create a config loader with the _latest_ defaults.
///
/// This loader will always set [`BehaviorMajorVersion::latest`].
/// This loader will always set [`BehaviorVersion::latest`].
///
/// # Examples
/// ```no_run
@@ -152,56 +152,56 @@ pub mod web_identity_token;
/// ```
#[cfg(feature = "behavior-version-latest")]
pub fn from_env() -> ConfigLoader {
    ConfigLoader::default().behavior_major_version(BehaviorMajorVersion::latest())
    ConfigLoader::default().behavior_version(BehaviorVersion::latest())
}

/// Load configuration from the environment
/// Load default configuration with the _latest_ defaults.
///
/// Convenience wrapper equivalent to `aws_config::load_defaults(BehaviorVersion::latest()).await`
#[cfg(feature = "behavior-version-latest")]
pub async fn load_from_env() -> SdkConfig {
    from_env().load().await
}

/// Create a config loader with the _latest_ defaults.
#[cfg(not(feature = "behavior-version-latest"))]
#[deprecated(
    note = "To enable the default behavior version, enable the `behavior-version-latest` feature. Alternatively, you can use [`from_env_with_version`]. This function will be removed in the next release."
    note = "Use the `aws_config::defaults` function. If you don't care about future default behavior changes, you can continue to use this function by enabling the `behavior-version-latest` feature. Doing so will make this deprecation notice go away."
)]
pub fn from_env() -> ConfigLoader {
    ConfigLoader::default().behavior_major_version(BehaviorMajorVersion::latest())
    ConfigLoader::default().behavior_version(BehaviorVersion::latest())
}

/// Load configuration from the environment
/// Load default configuration with the _latest_ defaults.
#[cfg(not(feature = "behavior-version-latest"))]
#[deprecated(
    note = "To enable the default behavior version, enable the `behavior-version-latest` feature. Alternatively, you can use [`load_from_env_with_version`]. This function will be removed in the next release."
    note = "Use the `aws_config::load_defaults` function. If you don't care about future default behavior changes, you can continue to use this function by enabling the `behavior-version-latest` feature. Doing so will make this deprecation notice go away."
)]
pub async fn load_from_env() -> SdkConfig {
    load_from_env_with_version(BehaviorMajorVersion::latest()).await
    load_defaults(BehaviorVersion::latest()).await
}

/// Create an environment loader for AWS Configuration
/// Create a config loader with the defaults for the given behavior version.
///
/// # Examples
/// ```no_run
/// # async fn create_config() {
/// use aws_config::BehaviorMajorVersion;
/// let config = aws_config::from_env_with_version(BehaviorMajorVersion::v2023_11_09())
/// use aws_config::BehaviorVersion;
/// let config = aws_config::defaults(BehaviorVersion::v2023_11_09())
///     .region("us-east-1")
///     .load()
///     .await;
/// # }
/// ```
pub fn from_env_with_version(version: BehaviorMajorVersion) -> ConfigLoader {
    ConfigLoader::default().behavior_major_version(version)
}

/// Load a default configuration from the environment
///
/// Convenience wrapper equivalent to `aws_config::from_env().load().await`
#[cfg(feature = "behavior-version-latest")]
pub async fn load_from_env() -> SdkConfig {
    from_env().load().await
pub fn defaults(version: BehaviorVersion) -> ConfigLoader {
    ConfigLoader::default().behavior_version(version)
}

/// Load a default configuration from the environment
/// Load default configuration with the given behavior version.
///
/// Convenience wrapper equivalent to `aws_config::from_env_with_version(BehaviorMajorVersion::latest()).load().await`
pub async fn load_from_env_with_version(version: BehaviorMajorVersion) -> SdkConfig {
    from_env_with_version(version).load().await
/// Convenience wrapper equivalent to `aws_config::defaults(behavior_version).load().await`
pub async fn load_defaults(version: BehaviorVersion) -> SdkConfig {
    defaults(version).load().await
}

mod loader {
@@ -214,7 +214,7 @@ mod loader {
    use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
    use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
    use aws_smithy_async::time::{SharedTimeSource, TimeSource};
    use aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion;
    use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
    use aws_smithy_runtime_api::client::http::HttpClient;
    use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache};
    use aws_smithy_runtime_api::shared::IntoShared;
@@ -262,16 +262,13 @@ mod loader {
        time_source: Option<SharedTimeSource>,
        env: Option<Env>,
        fs: Option<Fs>,
        behavior_major_version: Option<BehaviorMajorVersion>,
        behavior_version: Option<BehaviorVersion>,
    }

    impl ConfigLoader {
        /// Sets the [`BehaviorMajorVersion`] used to build [`SdkConfig`](aws_types::SdkConfig).
        pub fn behavior_major_version(
            mut self,
            behavior_major_version: BehaviorMajorVersion,
        ) -> Self {
            self.behavior_major_version = Some(behavior_major_version);
        /// Sets the [`BehaviorVersion`] used to build [`SdkConfig`](aws_types::SdkConfig).
        pub fn behavior_version(mut self, behavior_version: BehaviorVersion) -> Self {
            self.behavior_version = Some(behavior_version);
            self
        }

@@ -631,7 +628,7 @@ mod loader {
        ///     .enable_http1()
        ///     .build();
        /// let provider_config = ProviderConfig::default().with_tcp_connector(custom_https_connector);
        /// let shared_config = aws_config::from_env_with_version(BehaviorVersion::latest()).configure(provider_config).load().await;
        /// let shared_config = aws_config::defaults(BehaviorVersion::latest()).configure(provider_config).load().await;
        /// # }
        /// ```
        #[deprecated(
@@ -752,7 +749,7 @@ mod loader {
                .timeout_config(timeout_config)
                .time_source(time_source);

            builder.set_behavior_major_version(self.behavior_major_version);
            builder.set_behavior_version(self.behavior_version);
            builder.set_http_client(self.http_client);
            builder.set_app_name(app_name);
            builder.set_identity_cache(self.identity_cache);
@@ -782,8 +779,8 @@ mod loader {
    mod test {
        use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
        use crate::test_case::{no_traffic_client, InstantSleep};
        use crate::BehaviorMajorVersion;
        use crate::{from_env_with_version, ConfigLoader};
        use crate::BehaviorVersion;
        use crate::{defaults, ConfigLoader};
        use aws_credential_types::provider::ProvideCredentials;
        use aws_smithy_async::rt::sleep::TokioSleep;
        use aws_smithy_runtime::client::http::test_util::{infallible_client_fn, NeverClient};
@@ -804,7 +801,7 @@ mod loader {
            ]);
            let fs =
                Fs::from_slice(&[("test_config", "[profile custom]\nsdk-ua-app-id = correct")]);
            let loader = from_env_with_version(BehaviorMajorVersion::latest())
            let loader = defaults(BehaviorVersion::latest())
                .sleep_impl(TokioSleep::new())
                .env(env)
                .fs(fs)
@@ -848,7 +845,7 @@ mod loader {
        }

        fn base_conf() -> ConfigLoader {
            from_env_with_version(BehaviorMajorVersion::latest())
            defaults(BehaviorVersion::latest())
                .sleep_impl(InstantSleep)
                .http_client(no_traffic_client())
        }
@@ -878,7 +875,7 @@ mod loader {
        #[cfg(feature = "rustls")]
        #[tokio::test]
        async fn disable_default_credentials() {
            let config = from_env_with_version(BehaviorMajorVersion::latest())
            let config = defaults(BehaviorVersion::latest())
                .no_credentials()
                .load()
                .await;
@@ -894,7 +891,7 @@ mod loader {
                movable.fetch_add(1, Ordering::Relaxed);
                http::Response::new("ok!")
            });
            let config = from_env_with_version(BehaviorMajorVersion::latest())
            let config = defaults(BehaviorVersion::latest())
                .fs(Fs::from_slice(&[]))
                .env(Env::from_slice(&[]))
                .http_client(http_client.clone())
+1 −1
Original line number Diff line number Diff line
@@ -197,7 +197,7 @@ impl ProviderConfig {
            .time_source(self.time_source())
            .use_fips(self.use_fips().unwrap_or_default())
            .use_dual_stack(self.use_dual_stack().unwrap_or_default())
            .behavior_major_version(crate::BehaviorMajorVersion::latest());
            .behavior_version(crate::BehaviorVersion::latest());
        builder.set_http_client(self.http_client.clone());
        builder.set_sleep_impl(self.sleep_impl.clone());
        builder.build()
Loading