Skip to content

Commit

Permalink
Rename behavior versions and associated functions (#3204)
Browse files Browse the repository at this point in the history
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._
  • Loading branch information
jdisanti authored Nov 15, 2023
1 parent c830caa commit 572c5d7
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 138 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ 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"]
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"]
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-config/src/default_provider/app_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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())
Expand Down
89 changes: 43 additions & 46 deletions aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
//!
//! Load default SDK configuration:
//! ```no_run
//! use aws_config::BehaviorMajorVersion;
//! use aws_config::BehaviorVersion;
//! mod aws_sdk_dynamodb {
//! # pub struct Client;
//! # impl Client {
//! # pub fn new(config: &aws_types::SdkConfig) -> Self { Client }
//! # }
//! # }
//! # 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);
//! # }
//! ```
Expand Down Expand Up @@ -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)
Expand All @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand All @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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;
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/provider_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions aws/rust-runtime/aws-config/src/sso/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ impl Builder {
/// This will panic if any of the required fields are not given.
pub async fn build(mut self) -> SsoTokenProvider {
if self.sdk_config.is_none() {
self.sdk_config = Some(
crate::load_from_env_with_version(crate::BehaviorMajorVersion::latest()).await,
);
self.sdk_config = Some(crate::load_defaults(crate::BehaviorVersion::latest()).await);
}
self.build_with(Env::real(), Fs::real())
}
Expand Down Expand Up @@ -429,7 +427,7 @@ mod tests {
.sleep_impl(SharedAsyncSleep::new(sleep_impl))
// disable retry to simplify testing
.retry_config(RetryConfig::disabled())
.behavior_major_version(crate::BehaviorMajorVersion::latest())
.behavior_version(crate::BehaviorVersion::latest())
.build();
Self {
time_source,
Expand Down
14 changes: 7 additions & 7 deletions aws/rust-runtime/aws-config/src/sts/assume_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl AssumeRoleProviderBuilder {
pub async fn build(self) -> AssumeRoleProvider {
let mut conf = match self.sdk_config {
Some(conf) => conf,
None => crate::load_from_env_with_version(crate::BehaviorMajorVersion::latest()).await,
None => crate::load_defaults(crate::BehaviorVersion::latest()).await,
};
// ignore a identity cache set from SdkConfig
conf = conf
Expand Down Expand Up @@ -264,7 +264,7 @@ impl AssumeRoleProviderBuilder {
) -> AssumeRoleProvider {
let conf = match self.sdk_config {
Some(conf) => conf,
None => crate::load_from_env_with_version(crate::BehaviorMajorVersion::latest()).await,
None => crate::load_defaults(crate::BehaviorVersion::latest()).await,
};
let conf = conf
.into_builder()
Expand Down Expand Up @@ -334,7 +334,7 @@ mod test {
capture_request, ReplayEvent, StaticReplayClient,
};
use aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs;
use aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion;
use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
use aws_smithy_types::body::SdkBody;
use aws_types::os_shim_internal::Env;
use aws_types::region::Region;
Expand All @@ -352,7 +352,7 @@ mod test {
))
.http_client(http_client)
.region(Region::from_static("this-will-be-overridden"))
.behavior_major_version(crate::BehaviorMajorVersion::latest())
.behavior_version(crate::BehaviorVersion::latest())
.build();
let provider = AssumeRoleProvider::builder("myrole")
.configure(&sdk_config)
Expand All @@ -373,7 +373,7 @@ mod test {
async fn loads_region_from_sdk_config() {
let (http_client, request) = capture_request(None);
let sdk_config = SdkConfig::builder()
.behavior_major_version(crate::BehaviorMajorVersion::latest())
.behavior_version(crate::BehaviorVersion::latest())
.sleep_impl(SharedAsyncSleep::new(TokioSleep::new()))
.time_source(StaticTimeSource::new(
UNIX_EPOCH + Duration::from_secs(1234567890 - 120),
Expand Down Expand Up @@ -408,7 +408,7 @@ mod test {
.body(SdkBody::from(""))
.unwrap(),
));
let conf = crate::from_env_with_version(BehaviorMajorVersion::latest())
let conf = crate::defaults(BehaviorVersion::latest())
.env(Env::from_slice(&[
("AWS_ACCESS_KEY_ID", "123-key"),
("AWS_SECRET_ACCESS_KEY", "456"),
Expand Down Expand Up @@ -457,7 +457,7 @@ mod test {
.sleep_impl(SharedAsyncSleep::new(sleep))
.time_source(testing_time_source.clone())
.http_client(http_client)
.behavior_major_version(crate::BehaviorMajorVersion::latest())
.behavior_version(crate::BehaviorVersion::latest())
.build();
let credentials_list = std::sync::Arc::new(std::sync::Mutex::new(vec![
Credentials::new(
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-types/external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ allowed_external_types = [
"aws_smithy_runtime_api::client::http::SharedHttpClient",
"aws_smithy_runtime_api::client::identity::ResolveCachedIdentity",
"aws_smithy_runtime_api::client::identity::SharedIdentityCache",
"aws_smithy_runtime_api::client::behavior_version::BehaviorMajorVersion",
"aws_smithy_runtime_api::client::behavior_version::BehaviorVersion",
"aws_smithy_runtime_api::http::headers::Headers",
"aws_smithy_types::config_bag::storable::Storable",
"aws_smithy_types::config_bag::storable::StoreReplace",
Expand Down
Loading

0 comments on commit 572c5d7

Please sign in to comment.