diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 4dfdb3b13a..5668c75017 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -17,6 +17,77 @@ references = ["smithy-rs#1225"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "Velfi" +[[aws-sdk-rust]] +message = """ +`aws_types::config::Config` has been renamed to `aws_types::sdk_config::SdkConfig`. This is to better differentiate it +from service-specific configs like `aws_sdk_s3::Config`. If you were creating shared configs with +`aws_config::load_from_env()`, then you don't have to do anything. If you were directly referring to a shared config, +update your `use` statements and `struct` names. + +_Before:_ +```rust +use aws_types::config::Config; + +fn main() { + let config = Config::builder() + // config builder methods... + .build() + .await; +} +``` + +_After:_ +```rust +// We re-export this type from the root module so it's easier to reference +use aws_types::SdkConfig; + +fn main() { + let config = SdkConfig::builder() + // config builder methods... + .build() + .await; +} +``` +""" +references = ["aws-sdk-rust#406"] +meta = { "breaking" = true, "tada" = false, "bug" = false } +author = "Velfi" + +[[smithy-rs]] +message = """ +`aws_types::config::Config` has been renamed to `aws_types:sdk_config::SdkConfig`. This is to better differentiate it +from service-specific configs like `aws_s3_sdk::Config`. If you were creating shared configs with +`aws_config::load_from_env()`, then you don't have to do anything. If you were directly referring to a shared config, +update your `use` statements and `struct` names. + +_Before:_ +```rust +use aws_types::config::Config; + +fn main() { + let config = Config::builder() + // config builder methods... + .build() + .await; +} +``` + +_After:_ +```rust +use aws_types::SdkConfig; + +fn main() { + let config = SdkConfig::builder() + // config builder methods... + .build() + .await; +} +``` +""" +references = ["aws-sdk-rust#406"] +meta = { "breaking" = true, "tada" = false, "bug" = false } +author = "Velfi" + [[aws-sdk-rust]] message = "Enable presigning for S3 operations UploadPart and DeleteObject" references = ["aws-sdk-rust#475", "aws-sdk-rust#473"] diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 1f7bd87225..1af1024871 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -10,7 +10,7 @@ //! [`from_env`]/[`ConfigLoader`] or ad-hoc individual credential and region providers. //! //! [`ConfigLoader`](ConfigLoader) can combine different configuration sources into an AWS shared-config: -//! [`Config`](aws_types::config::Config). [`Config`](aws_types::config::Config) can be used configure +//! [`SdkConfig`](aws_types::SdkConfig). [`SdkConfig`](aws_types::SdkConfig) can be used configure //! an AWS service client. //! //! # Examples @@ -20,7 +20,7 @@ //! # mod aws_sdk_dynamodb { //! # pub struct Client; //! # impl Client { -//! # pub fn new(config: &aws_types::config::Config) -> Self { Client } +//! # pub fn new(config: &aws_types::SdkConfig) -> Self { Client } //! # } //! # } //! # async fn docs() { @@ -34,7 +34,7 @@ //! # mod aws_sdk_dynamodb { //! # pub struct Client; //! # impl Client { -//! # pub fn new(config: &aws_types::config::Config) -> Self { Client } +//! # pub fn new(config: &aws_types::SdkConfig) -> Self { Client } //! # } //! # } //! # async fn docs() { @@ -90,7 +90,6 @@ pub use aws_smithy_types::timeout::TimeoutConfig; // Re-export types from aws-types pub use aws_types::app_name::{AppName, InvalidAppName}; -pub use aws_types::config::Config; /// Create an environment loader for AWS Configuration /// @@ -108,7 +107,7 @@ pub fn from_env() -> ConfigLoader { /// Load a default configuration from the environment /// /// Convenience wrapper equivalent to `aws_config::from_env().load().await` -pub async fn load_from_env() -> aws_types::config::Config { +pub async fn load_from_env() -> aws_types::SdkConfig { from_env().load().await } @@ -124,14 +123,14 @@ mod loader { use aws_smithy_types::retry::RetryConfig; use aws_smithy_types::timeout::TimeoutConfig; use aws_types::app_name::AppName; - use aws_types::config::Config; use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider}; + use aws_types::SdkConfig; use crate::default_provider::{app_name, credentials, region, retry_config, timeout_config}; use crate::meta::region::ProvideRegion; use crate::provider_config::ProviderConfig; - /// Load a cross-service [`Config`](aws_types::config::Config) from the environment + /// Load a cross-service [`SdkConfig`](aws_types::SdkConfig) from the environment /// /// This builder supports overriding individual components of the generated config. Overriding a component /// will skip the standard resolution chain from **for that component**. For example, @@ -150,7 +149,7 @@ mod loader { } impl ConfigLoader { - /// Override the region used to build [`Config`](aws_types::config::Config). + /// Override the region used to build [`SdkConfig`](aws_types::SdkConfig). /// /// # Examples /// ```no_run @@ -166,7 +165,7 @@ mod loader { self } - /// Override the retry_config used to build [`Config`](aws_types::config::Config). + /// Override the retry_config used to build [`SdkConfig`](aws_types::SdkConfig). /// /// # Examples /// ```no_run @@ -182,7 +181,7 @@ mod loader { self } - /// Override the timeout config used to build [`Config`](aws_types::config::Config). + /// Override the timeout config used to build [`SdkConfig`](aws_types::SdkConfig). /// **Note: This only sets timeouts for calls to AWS services.** Timeouts for the credentials /// provider chain are configured separately. /// @@ -211,13 +210,13 @@ mod loader { self } - /// Override the [`HttpConnector`] used to build [`Config`](aws_types::config::Config). + /// Override the [`HttpConnector`] used to build [`SdkConfig`](aws_types::SdkConfig). pub fn http_connector(mut self, http_connector: HttpConnector) -> Self { self.http_connector = Some(http_connector); self } - /// Override the credentials provider used to build [`Config`](aws_types::config::Config). + /// Override the credentials provider used to build [`SdkConfig`](aws_types::SdkConfig). /// /// # Examples /// @@ -273,8 +272,8 @@ mod loader { /// /// NOTE: When an override is provided, the default implementation is **not** used as a fallback. /// This means that if you provide a region provider that does not return a region, no region will - /// be set in the resulting [`Config`](aws_types::config::Config) - pub async fn load(self) -> aws_types::config::Config { + /// be set in the resulting [`SdkConfig`](aws_types::SdkConfig) + pub async fn load(self) -> SdkConfig { let conf = self.provider_config.unwrap_or_default(); let region = if let Some(provider) = self.region { provider.region().await @@ -344,7 +343,7 @@ mod loader { SharedCredentialsProvider::new(builder.build().await) }; - let mut builder = Config::builder() + let mut builder = SdkConfig::builder() .region(region) .retry_config(retry_config) .timeout_config(timeout_config) diff --git a/aws/rust-runtime/aws-types/src/config.rs b/aws/rust-runtime/aws-types/src/config.rs index c2cf0d1b27..71ed49fd5f 100644 --- a/aws/rust-runtime/aws-types/src/config.rs +++ b/aws/rust-runtime/aws-types/src/config.rs @@ -5,352 +5,10 @@ #![deny(missing_docs)] -//! AWS Shared Config +//! AWS Shared Config _(deprecated, replaced with [`sdk_config`](crate::sdk_config))_ //! //! This module contains an shared configuration representation that is agnostic from a specific service. -use std::sync::Arc; - -use aws_smithy_async::rt::sleep::AsyncSleep; -use aws_smithy_client::http_connector::HttpConnector; -use aws_smithy_types::retry::RetryConfig; -use aws_smithy_types::timeout::TimeoutConfig; - -use crate::app_name::AppName; -use crate::credentials::SharedCredentialsProvider; -use crate::region::Region; - +#[deprecated(since = "0.9.0", note = "renamed to crate::SdkConfig")] /// AWS Shared Configuration -#[derive(Debug, Clone)] -pub struct Config { - app_name: Option, - credentials_provider: Option, - region: Option, - retry_config: Option, - sleep_impl: Option>, - timeout_config: Option, - http_connector: Option, -} - -/// Builder for AWS Shared Configuration -#[derive(Debug, Default)] -pub struct Builder { - app_name: Option, - credentials_provider: Option, - region: Option, - retry_config: Option, - sleep_impl: Option>, - timeout_config: Option, - http_connector: Option, -} - -impl Builder { - /// Set the region for the builder - /// - /// # Examples - /// ```rust - /// use aws_types::config::Config; - /// use aws_types::region::Region; - /// let config = Config::builder().region(Region::new("us-east-1")).build(); - /// ``` - pub fn region(mut self, region: impl Into>) -> Self { - self.set_region(region); - self - } - - /// Set the region for the builder - /// - /// # Examples - /// ```rust - /// fn region_override() -> Option { - /// // ... - /// # None - /// } - /// use aws_types::config::Config; - /// use aws_types::region::Region; - /// let mut builder = Config::builder(); - /// if let Some(region) = region_override() { - /// builder.set_region(region); - /// } - /// let config = builder.build(); - /// ``` - pub fn set_region(&mut self, region: impl Into>) -> &mut Self { - self.region = region.into(); - self - } - - /// Set the retry_config for the builder - /// - /// # Examples - /// ```rust - /// use aws_types::config::Config; - /// use aws_smithy_types::retry::RetryConfig; - /// - /// let retry_config = RetryConfig::new().with_max_attempts(5); - /// let config = Config::builder().retry_config(retry_config).build(); - /// ``` - pub fn retry_config(mut self, retry_config: RetryConfig) -> Self { - self.set_retry_config(Some(retry_config)); - self - } - - /// Set the retry_config for the builder - /// - /// # Examples - /// ```rust - /// use aws_types::config::{Config, Builder}; - /// use aws_smithy_types::retry::RetryConfig; - /// - /// fn disable_retries(builder: &mut Builder) { - /// let retry_config = RetryConfig::new().with_max_attempts(1); - /// builder.set_retry_config(Some(retry_config)); - /// } - /// - /// let mut builder = Config::builder(); - /// disable_retries(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_retry_config(&mut self, retry_config: Option) -> &mut Self { - self.retry_config = retry_config; - self - } - - /// Set the [`TimeoutConfig`] for the builder - /// - /// # Examples - /// - /// ```rust - /// # use std::time::Duration; - /// use aws_types::config::Config; - /// use aws_smithy_types::timeout::TimeoutConfig; - /// - /// let timeout_config = TimeoutConfig::new() - /// .with_api_call_attempt_timeout(Some(Duration::from_secs(1))); - /// let config = Config::builder().timeout_config(timeout_config).build(); - /// ``` - pub fn timeout_config(mut self, timeout_config: TimeoutConfig) -> Self { - self.set_timeout_config(Some(timeout_config)); - self - } - - /// Set the [`TimeoutConfig`] for the builder - /// - /// # Examples - /// ```rust - /// # use std::time::Duration; - /// use aws_types::config::{Config, Builder}; - /// use aws_smithy_types::timeout::TimeoutConfig; - /// - /// fn set_preferred_timeouts(builder: &mut Builder) { - /// let timeout_config = TimeoutConfig::new() - /// .with_api_call_attempt_timeout(Some(Duration::from_secs(2))) - /// .with_api_call_timeout(Some(Duration::from_secs(5))); - /// builder.set_timeout_config(Some(timeout_config)); - /// } - /// - /// let mut builder = Config::builder(); - /// set_preferred_timeouts(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_timeout_config(&mut self, timeout_config: Option) -> &mut Self { - self.timeout_config = timeout_config; - self - } - - #[doc(hidden)] - /// Set the sleep implementation for the builder. The sleep implementation is used to create - /// timeout futures. - /// - /// # Examples - /// - /// ```rust - /// use std::sync::Arc; - /// use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep}; - /// use aws_types::config::Config; - /// - /// ##[derive(Debug)] - /// pub struct ForeverSleep; - /// - /// impl AsyncSleep for ForeverSleep { - /// fn sleep(&self, duration: std::time::Duration) -> Sleep { - /// Sleep::new(std::future::pending()) - /// } - /// } - /// - /// let sleep_impl = Arc::new(ForeverSleep); - /// let config = Config::builder().sleep_impl(sleep_impl).build(); - /// ``` - pub fn sleep_impl(mut self, sleep_impl: Arc) -> Self { - self.set_sleep_impl(Some(sleep_impl)); - self - } - - #[doc(hidden)] - /// Set the sleep implementation for the builder. The sleep implementation is used to create - /// timeout futures. - /// - /// # Examples - /// ```rust - /// # use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep}; - /// # use aws_types::config::{Builder, Config}; - /// #[derive(Debug)] - /// pub struct ForeverSleep; - /// - /// impl AsyncSleep for ForeverSleep { - /// fn sleep(&self, duration: std::time::Duration) -> Sleep { - /// Sleep::new(std::future::pending()) - /// } - /// } - /// - /// fn set_never_ending_sleep_impl(builder: &mut Builder) { - /// let sleep_impl = std::sync::Arc::new(ForeverSleep); - /// builder.set_sleep_impl(Some(sleep_impl)); - /// } - /// - /// let mut builder = Config::builder(); - /// set_never_ending_sleep_impl(&mut builder); - /// let config = builder.build(); - /// ``` - pub fn set_sleep_impl(&mut self, sleep_impl: Option>) -> &mut Self { - self.sleep_impl = sleep_impl; - self - } - - /// Set the credentials provider for the builder - /// - /// # Examples - /// ```rust - /// use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider}; - /// use aws_types::config::Config; - /// fn make_provider() -> impl ProvideCredentials { - /// // ... - /// # use aws_types::Credentials; - /// # Credentials::new("test", "test", None, None, "example") - /// } - /// - /// let config = Config::builder() - /// .credentials_provider(SharedCredentialsProvider::new(make_provider())) - /// .build(); - /// ``` - pub fn credentials_provider(mut self, provider: SharedCredentialsProvider) -> Self { - self.set_credentials_provider(Some(provider)); - self - } - - /// Set the credentials provider for the builder - /// - /// # Examples - /// ```rust - /// use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider}; - /// use aws_types::config::Config; - /// fn make_provider() -> impl ProvideCredentials { - /// // ... - /// # use aws_types::Credentials; - /// # Credentials::new("test", "test", None, None, "example") - /// } - /// - /// fn override_provider() -> bool { - /// // ... - /// # true - /// } - /// - /// let mut builder = Config::builder(); - /// if override_provider() { - /// builder.set_credentials_provider(Some(SharedCredentialsProvider::new(make_provider()))); - /// } - /// let config = builder.build(); - /// ``` - pub fn set_credentials_provider( - &mut self, - provider: Option, - ) -> &mut Self { - self.credentials_provider = provider; - self - } - - /// Sets the name of the app that is using the client. - /// - /// This _optional_ name is used to identify the application in the user agent that - /// gets sent along with requests. - pub fn app_name(mut self, app_name: AppName) -> Self { - self.set_app_name(Some(app_name)); - self - } - - /// Sets the name of the app that is using the client. - /// - /// This _optional_ name is used to identify the application in the user agent that - /// gets sent along with requests. - pub fn set_app_name(&mut self, app_name: Option) -> &mut Self { - self.app_name = app_name; - self - } - - /// Sets the HTTP connector that clients will use to make HTTP requests. - pub fn http_connector(mut self, http_connector: HttpConnector) -> Self { - self.set_http_connector(Some(http_connector)); - self - } - - /// Sets the HTTP connector that clients will use to make HTTP requests. - pub fn set_http_connector(&mut self, http_connector: Option) -> &mut Self { - self.http_connector = http_connector; - self - } - - /// Build a [`Config`](Config) from this builder - pub fn build(self) -> Config { - Config { - app_name: self.app_name, - credentials_provider: self.credentials_provider, - region: self.region, - retry_config: self.retry_config, - sleep_impl: self.sleep_impl, - timeout_config: self.timeout_config, - http_connector: self.http_connector, - } - } -} - -impl Config { - /// Configured region - pub fn region(&self) -> Option<&Region> { - self.region.as_ref() - } - - /// Configured retry config - pub fn retry_config(&self) -> Option<&RetryConfig> { - self.retry_config.as_ref() - } - - /// Configured timeout config - pub fn timeout_config(&self) -> Option<&TimeoutConfig> { - self.timeout_config.as_ref() - } - - #[doc(hidden)] - /// Configured sleep implementation - pub fn sleep_impl(&self) -> Option> { - self.sleep_impl.clone() - } - - /// Configured credentials provider - pub fn credentials_provider(&self) -> Option<&SharedCredentialsProvider> { - self.credentials_provider.as_ref() - } - - /// Configured app name - pub fn app_name(&self) -> Option<&AppName> { - self.app_name.as_ref() - } - - /// Configured HTTP Connector - pub fn http_connector(&self) -> Option<&HttpConnector> { - self.http_connector.as_ref() - } - - /// Config builder - pub fn builder() -> Builder { - Builder::default() - } -} +pub type Config = super::SdkConfig; diff --git a/aws/rust-runtime/aws-types/src/lib.rs b/aws/rust-runtime/aws-types/src/lib.rs index 896fc15f64..db34a29556 100644 --- a/aws/rust-runtime/aws-types/src/lib.rs +++ b/aws/rust-runtime/aws-types/src/lib.rs @@ -15,14 +15,17 @@ pub mod app_name; pub mod build_metadata; +#[deprecated(since = "0.9.0", note = "renamed to sdk_config")] pub mod config; pub mod credentials; #[doc(hidden)] pub mod os_shim_internal; pub mod region; +pub mod sdk_config; pub use aws_smithy_client::http_connector; pub use credentials::Credentials; +pub use sdk_config::SdkConfig; use std::borrow::Cow; diff --git a/aws/rust-runtime/aws-types/src/sdk_config.rs b/aws/rust-runtime/aws-types/src/sdk_config.rs new file mode 100644 index 0000000000..e72e3d5a67 --- /dev/null +++ b/aws/rust-runtime/aws-types/src/sdk_config.rs @@ -0,0 +1,356 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#![deny(missing_docs)] + +//! AWS Shared Config +//! +//! This module contains an shared configuration representation that is agnostic from a specific service. + +use std::sync::Arc; + +use aws_smithy_async::rt::sleep::AsyncSleep; +use aws_smithy_client::http_connector::HttpConnector; +use aws_smithy_types::retry::RetryConfig; +use aws_smithy_types::timeout::TimeoutConfig; + +use crate::app_name::AppName; +use crate::credentials::SharedCredentialsProvider; +use crate::region::Region; + +/// AWS Shared Configuration +#[derive(Debug, Clone)] +pub struct SdkConfig { + app_name: Option, + credentials_provider: Option, + region: Option, + retry_config: Option, + sleep_impl: Option>, + timeout_config: Option, + http_connector: Option, +} + +/// Builder for AWS Shared Configuration +#[derive(Debug, Default)] +pub struct Builder { + app_name: Option, + credentials_provider: Option, + region: Option, + retry_config: Option, + sleep_impl: Option>, + timeout_config: Option, + http_connector: Option, +} + +impl Builder { + /// Set the region for the builder + /// + /// # Examples + /// ```rust + /// use aws_types::SdkConfig; + /// use aws_types::region::Region; + /// let config = SdkConfig::builder().region(Region::new("us-east-1")).build(); + /// ``` + pub fn region(mut self, region: impl Into>) -> Self { + self.set_region(region); + self + } + + /// Set the region for the builder + /// + /// # Examples + /// ```rust + /// fn region_override() -> Option { + /// // ... + /// # None + /// } + /// use aws_types::SdkConfig; + /// use aws_types::region::Region; + /// let mut builder = SdkConfig::builder(); + /// if let Some(region) = region_override() { + /// builder.set_region(region); + /// } + /// let config = builder.build(); + /// ``` + pub fn set_region(&mut self, region: impl Into>) -> &mut Self { + self.region = region.into(); + self + } + + /// Set the retry_config for the builder + /// + /// # Examples + /// ```rust + /// use aws_types::SdkConfig; + /// use aws_smithy_types::retry::RetryConfig; + /// + /// let retry_config = RetryConfig::new().with_max_attempts(5); + /// let config = SdkConfig::builder().retry_config(retry_config).build(); + /// ``` + pub fn retry_config(mut self, retry_config: RetryConfig) -> Self { + self.set_retry_config(Some(retry_config)); + self + } + + /// Set the retry_config for the builder + /// + /// # Examples + /// ```rust + /// use aws_types::sdk_config::{SdkConfig, Builder}; + /// use aws_smithy_types::retry::RetryConfig; + /// + /// fn disable_retries(builder: &mut Builder) { + /// let retry_config = RetryConfig::new().with_max_attempts(1); + /// builder.set_retry_config(Some(retry_config)); + /// } + /// + /// let mut builder = SdkConfig::builder(); + /// disable_retries(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_retry_config(&mut self, retry_config: Option) -> &mut Self { + self.retry_config = retry_config; + self + } + + /// Set the [`TimeoutConfig`] for the builder + /// + /// # Examples + /// + /// ```rust + /// # use std::time::Duration; + /// use aws_types::SdkConfig; + /// use aws_smithy_types::timeout::TimeoutConfig; + /// + /// let timeout_config = TimeoutConfig::new() + /// .with_api_call_attempt_timeout(Some(Duration::from_secs(1))); + /// let config = SdkConfig::builder().timeout_config(timeout_config).build(); + /// ``` + pub fn timeout_config(mut self, timeout_config: TimeoutConfig) -> Self { + self.set_timeout_config(Some(timeout_config)); + self + } + + /// Set the [`TimeoutConfig`] for the builder + /// + /// # Examples + /// ```rust + /// # use std::time::Duration; + /// use aws_types::sdk_config::{SdkConfig, Builder}; + /// use aws_smithy_types::timeout::TimeoutConfig; + /// + /// fn set_preferred_timeouts(builder: &mut Builder) { + /// let timeout_config = TimeoutConfig::new() + /// .with_api_call_attempt_timeout(Some(Duration::from_secs(2))) + /// .with_api_call_timeout(Some(Duration::from_secs(5))); + /// builder.set_timeout_config(Some(timeout_config)); + /// } + /// + /// let mut builder = SdkConfig::builder(); + /// set_preferred_timeouts(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_timeout_config(&mut self, timeout_config: Option) -> &mut Self { + self.timeout_config = timeout_config; + self + } + + #[doc(hidden)] + /// Set the sleep implementation for the builder. The sleep implementation is used to create + /// timeout futures. + /// + /// # Examples + /// + /// ```rust + /// use std::sync::Arc; + /// use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep}; + /// use aws_types::SdkConfig; + /// + /// ##[derive(Debug)] + /// pub struct ForeverSleep; + /// + /// impl AsyncSleep for ForeverSleep { + /// fn sleep(&self, duration: std::time::Duration) -> Sleep { + /// Sleep::new(std::future::pending()) + /// } + /// } + /// + /// let sleep_impl = Arc::new(ForeverSleep); + /// let config = SdkConfig::builder().sleep_impl(sleep_impl).build(); + /// ``` + pub fn sleep_impl(mut self, sleep_impl: Arc) -> Self { + self.set_sleep_impl(Some(sleep_impl)); + self + } + + #[doc(hidden)] + /// Set the sleep implementation for the builder. The sleep implementation is used to create + /// timeout futures. + /// + /// # Examples + /// ```rust + /// # use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep}; + /// # use aws_types::sdk_config::{Builder, SdkConfig}; + /// #[derive(Debug)] + /// pub struct ForeverSleep; + /// + /// impl AsyncSleep for ForeverSleep { + /// fn sleep(&self, duration: std::time::Duration) -> Sleep { + /// Sleep::new(std::future::pending()) + /// } + /// } + /// + /// fn set_never_ending_sleep_impl(builder: &mut Builder) { + /// let sleep_impl = std::sync::Arc::new(ForeverSleep); + /// builder.set_sleep_impl(Some(sleep_impl)); + /// } + /// + /// let mut builder = SdkConfig::builder(); + /// set_never_ending_sleep_impl(&mut builder); + /// let config = builder.build(); + /// ``` + pub fn set_sleep_impl(&mut self, sleep_impl: Option>) -> &mut Self { + self.sleep_impl = sleep_impl; + self + } + + /// Set the credentials provider for the builder + /// + /// # Examples + /// ```rust + /// use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider}; + /// use aws_types::SdkConfig; + /// fn make_provider() -> impl ProvideCredentials { + /// // ... + /// # use aws_types::Credentials; + /// # Credentials::new("test", "test", None, None, "example") + /// } + /// + /// let config = SdkConfig::builder() + /// .credentials_provider(SharedCredentialsProvider::new(make_provider())) + /// .build(); + /// ``` + pub fn credentials_provider(mut self, provider: SharedCredentialsProvider) -> Self { + self.set_credentials_provider(Some(provider)); + self + } + + /// Set the credentials provider for the builder + /// + /// # Examples + /// ```rust + /// use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider}; + /// use aws_types::SdkConfig; + /// fn make_provider() -> impl ProvideCredentials { + /// // ... + /// # use aws_types::Credentials; + /// # Credentials::new("test", "test", None, None, "example") + /// } + /// + /// fn override_provider() -> bool { + /// // ... + /// # true + /// } + /// + /// let mut builder = SdkConfig::builder(); + /// if override_provider() { + /// builder.set_credentials_provider(Some(SharedCredentialsProvider::new(make_provider()))); + /// } + /// let config = builder.build(); + /// ``` + pub fn set_credentials_provider( + &mut self, + provider: Option, + ) -> &mut Self { + self.credentials_provider = provider; + self + } + + /// Sets the name of the app that is using the client. + /// + /// This _optional_ name is used to identify the application in the user agent that + /// gets sent along with requests. + pub fn app_name(mut self, app_name: AppName) -> Self { + self.set_app_name(Some(app_name)); + self + } + + /// Sets the name of the app that is using the client. + /// + /// This _optional_ name is used to identify the application in the user agent that + /// gets sent along with requests. + pub fn set_app_name(&mut self, app_name: Option) -> &mut Self { + self.app_name = app_name; + self + } + + /// Sets the HTTP connector that clients will use to make HTTP requests. + pub fn http_connector(mut self, http_connector: HttpConnector) -> Self { + self.set_http_connector(Some(http_connector)); + self + } + + /// Sets the HTTP connector that clients will use to make HTTP requests. + pub fn set_http_connector(&mut self, http_connector: Option) -> &mut Self { + self.http_connector = http_connector; + self + } + + /// Build a [`SdkConfig`](SdkConfig) from this builder + pub fn build(self) -> SdkConfig { + SdkConfig { + app_name: self.app_name, + credentials_provider: self.credentials_provider, + region: self.region, + retry_config: self.retry_config, + sleep_impl: self.sleep_impl, + timeout_config: self.timeout_config, + http_connector: self.http_connector, + } + } +} + +impl SdkConfig { + /// Configured region + pub fn region(&self) -> Option<&Region> { + self.region.as_ref() + } + + /// Configured retry config + pub fn retry_config(&self) -> Option<&RetryConfig> { + self.retry_config.as_ref() + } + + /// Configured timeout config + pub fn timeout_config(&self) -> Option<&TimeoutConfig> { + self.timeout_config.as_ref() + } + + #[doc(hidden)] + /// Configured sleep implementation + pub fn sleep_impl(&self) -> Option> { + self.sleep_impl.clone() + } + + /// Configured credentials provider + pub fn credentials_provider(&self) -> Option<&SharedCredentialsProvider> { + self.credentials_provider.as_ref() + } + + /// Configured app name + pub fn app_name(&self) -> Option<&AppName> { + self.app_name.as_ref() + } + + /// Configured HTTP Connector + pub fn http_connector(&self) -> Option<&HttpConnector> { + self.http_connector.as_ref() + } + + /// Config builder + pub fn builder() -> Builder { + Builder::default() + } +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt index 8ed210f7c7..931dc5e7ea 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt @@ -29,7 +29,7 @@ val DECORATORS = listOf( IntegrationTestDecorator(), AwsFluentClientDecorator(), CrateLicenseDecorator(), - SharedConfigDecorator(), + SdkConfigDecorator(), ServiceConfigDecorator(), AwsPresigningDecorator(), AwsReadmeDecorator(), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 3dc14dcb1b..777372c99b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -151,8 +151,8 @@ private class AwsFluentClientExtensions(types: Types) { /// Creates a new client from a shared config. ##[cfg(any(feature = "rustls", feature = "native-tls"))] - pub fn new(config: &#{aws_types}::config::Config) -> Self { - Self::from_conf(config.into()) + pub fn new(sdk_config: &#{aws_types}::sdk_config::SdkConfig) -> Self { + Self::from_conf(sdk_config.into()) } /// Creates a new client from the service [`Config`](crate::Config). diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SharedConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt similarity index 70% rename from aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SharedConfigDecorator.kt rename to aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt index a1b52fd712..f63e4bae21 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SharedConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt @@ -18,13 +18,13 @@ import software.amazon.smithy.rust.codegen.smithy.generators.config.ConfigCustom import software.amazon.smithy.rust.codegen.smithy.generators.config.ServiceConfig /** - * Adds functionality for constructing ::Config objects from aws_types::config::Config (SharedConfig) + * Adds functionality for constructing `::Config` objects from `aws_types::SdkConfig`s * - * - `From<&aws_types::config::Config> for ::config::Builder`: Enabling customization - * - `pub fn new(&aws_types::config::Config) -> ::Config`: Direct construction without customization + * - `From<&aws_types::SdkConfig> for ::config::Builder`: Enabling customization + * - `pub fn new(&aws_types::SdkConfig) -> ::Config`: Direct construction without customization */ -class SharedConfigDecorator : RustCodegenDecorator { - override val name: String = "SharedConfig" +class SdkConfigDecorator : RustCodegenDecorator { + override val name: String = "SdkConfig" override val order: Byte = 0 override fun configCustomizations( @@ -36,14 +36,14 @@ class SharedConfigDecorator : RustCodegenDecorator { override fun extras(codegenContext: CodegenContext, rustCrate: RustCrate) { val codegenScope = arrayOf( - "Config" to awsTypes(runtimeConfig = codegenContext.runtimeConfig).asType().member("config::Config") + "SdkConfig" to awsTypes(runtimeConfig = codegenContext.runtimeConfig).asType().member("sdk_config::SdkConfig") ) rustCrate.withModule(RustModule.Config) { - // !!NOTE!! As more items are added to aws_types::config::Config, use them here to configure the config builder + // !!NOTE!! As more items are added to aws_types::SdkConfig, use them here to configure the config builder it.rustTemplate( """ - impl From<&#{Config}> for Builder { - fn from(input: &#{Config}) -> Self { + impl From<&#{SdkConfig}> for Builder { + fn from(input: &#{SdkConfig}) -> Self { let mut builder = Builder::default(); builder = builder.region(input.region().cloned()); builder.set_retry_config(input.retry_config().cloned()); @@ -55,9 +55,9 @@ class SharedConfigDecorator : RustCodegenDecorator { } } - impl From<&#{Config}> for Config { - fn from(config: &#{Config}) -> Self { - Builder::from(config).build() + impl From<&#{SdkConfig}> for Config { + fn from(sdk_config: &#{SdkConfig}) -> Self { + Builder::from(sdk_config).build() } } """, @@ -69,15 +69,15 @@ class SharedConfigDecorator : RustCodegenDecorator { class NewFromShared(runtimeConfig: RuntimeConfig) : ConfigCustomization() { private val codegenScope = arrayOf( - "Config" to awsTypes(runtimeConfig = runtimeConfig).asType().member("config::Config") + "SdkConfig" to awsTypes(runtimeConfig = runtimeConfig).asType().member("sdk_config::SdkConfig") ) override fun section(section: ServiceConfig): Writable { return when (section) { ServiceConfig.ConfigImpl -> writable { rustTemplate( """ - /// Creates a new [service config](crate::Config) from a [shared `config`](aws_types::config::Config). - pub fn new(config: &#{Config}) -> Self { + /// Creates a new [service config](crate::Config) from a [shared `config`](#{SdkConfig}). + pub fn new(config: &#{SdkConfig}) -> Self { Builder::from(config).build() } """, diff --git a/aws/sdk/integration-tests/dynamodb/tests/cloning.rs b/aws/sdk/integration-tests/dynamodb/tests/cloning.rs index 5e840f13fc..7b4a9ffd09 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/cloning.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/cloning.rs @@ -10,7 +10,7 @@ use aws_types::Credentials; // compiling this function validates that fluent builders are cloneable #[allow(dead_code)] async fn ensure_builders_clone() { - let shared_config = aws_types::config::Config::builder() + let shared_config = aws_types::SdkConfig::builder() .region(Region::new("us-east-4")) .credentials_provider(SharedCredentialsProvider::new(Credentials::new( "asdf", "asdf", None, None, "test", diff --git a/aws/sdk/integration-tests/dynamodb/tests/shared-config.rs b/aws/sdk/integration-tests/dynamodb/tests/shared-config.rs index 10f5853d15..b47ebea4c7 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/shared-config.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/shared-config.rs @@ -9,7 +9,7 @@ use http::Uri; /// Iterative test of loading clients from shared configuration #[tokio::test] async fn shared_config_testbed() { - let shared_config = aws_types::config::Config::builder() + let shared_config = aws_types::SdkConfig::builder() .region(Region::new("us-east-4")) .build(); let conf = aws_sdk_dynamodb::config::Builder::from(&shared_config)