Skip to content

Commit 0b32a89

Browse files
authored
Lots of doc tweaks and cleanups (smithy-lang#693)
1 parent 60b6635 commit 0b32a89

File tree

23 files changed

+136
-81
lines changed

23 files changed

+136
-81
lines changed

aws/rust-runtime/aws-config/src/default_provider.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6-
//! Default Provider chains for [`region`](default_provider::region) and credentials (TODO)
6+
//! Default Provider chains for [`region`](default_provider::region) and [`credentials`](default_provider::credentials).
7+
//!
8+
//! Unless specific configuration is required, these should be constructed via [`ConfigLoader`](crate::ConfigLoader).
9+
//!
10+
//!
711
812
/// Default region provider chain
913
pub mod region {

aws/rust-runtime/aws-config/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#![deny(missing_docs)]
22

3-
//! `aws-config` provides implementations of region, credential (todo), and connector (todo) resolution.
3+
//! `aws-config` provides implementations of region, credential resolution.
4+
//!
5+
//! These implementations can be used either via the default chain implementation
6+
//! [`from_env`]/[`ConfigLoader`] or ad-hoc individual credential and region providers.
47
//!
5-
//! These implementations can be used either adhoc or via [`from_env`](from_env)/[`ConfigLoader`](ConfigLoader).
68
//! [`ConfigLoader`](ConfigLoader) can combine different configuration sources into an AWS shared-config:
79
//! [`Config`](aws_types::config::Config). [`Config`](aws_types::config::Config) can be used configure
810
//! an AWS service client.
911
//!
10-
//! ## Examples
12+
//! # Examples
1113
//! Load default SDK configuration:
1214
//! ```rust
1315
//! # mod aws_sdk_dynamodb {
@@ -66,7 +68,7 @@ pub mod provider_config;
6668

6769
/// Create an environment loader for AWS Configuration
6870
///
69-
/// ## Example
71+
/// # Examples
7072
/// ```rust
7173
/// # async fn create_config() {
7274
/// use aws_types::region::Region;
@@ -112,7 +114,7 @@ mod loader {
112114
impl ConfigLoader {
113115
/// Override the region used to build [`Config`](aws_types::config::Config).
114116
///
115-
/// # Example
117+
/// # Examples
116118
/// ```rust
117119
/// # async fn create_config() {
118120
/// use aws_types::region::Region;
@@ -127,7 +129,7 @@ mod loader {
127129
}
128130

129131
/// Override the credentials provider used to build [`Config`](aws_types::config::Config).
130-
/// # Example
132+
/// # Examples
131133
/// Override the credentials provider but load the default value for region:
132134
/// ```rust
133135
/// # use aws_types::Credentials;

aws/rust-runtime/aws-config/src/meta/credentials/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::Instrument;
1818
/// the next provider will be checked.
1919
/// * Finally, if a provider returns any other error condition, an error will be returned immediately.
2020
///
21-
/// ## Example
21+
/// # Examples
2222
/// ```rust
2323
/// use aws_config::meta::credentials::CredentialsProviderChain;
2424
/// use aws_types::Credentials;

aws/rust-runtime/aws-config/src/meta/credentials/credential_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
/// to create an [`ProvideCredentials`] implementation from an async block that returns
3737
/// a [`credentials::Result`].
3838
///
39-
/// # Example
39+
/// # Examples
4040
///
4141
/// ```
4242
/// use aws_types::Credentials;

aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod builder {
125125

126126
/// Builder for constructing a [`LazyCachingCredentialsProvider`].
127127
///
128-
/// # Example
128+
/// # Examples
129129
///
130130
/// ```
131131
/// use aws_types::Credentials;

aws/rust-runtime/aws-config/src/meta/credentials/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
//! Credential providers that augment an existing credentials providers to add functionality
7+
68
mod chain;
79
pub use chain::CredentialsProviderChain;
810

aws/rust-runtime/aws-config/src/meta/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6-
/// Region Providers
76
pub mod region;
87

9-
/// Credential Providers
108
pub mod credentials;

aws/rust-runtime/aws-config/src/meta/region.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
//! Region providers that augment existing providers with new functionality
7+
68
use aws_types::region::Region;
79
use std::borrow::Cow;
810
use std::fmt::Debug;
911
use tracing::Instrument;
1012

1113
/// Load a region by selecting the first from a series of region providers.
1214
///
13-
/// # Example
15+
/// # Examples
1416
/// ```rust
1517
/// use aws_types::region::Region;
1618
/// use std::env;

aws/rust-runtime/aws-config/src/profile/credentials.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub struct Builder {
293293
impl Builder {
294294
/// Override the configuration for the [`ProfileFileCredentialsProvider`]
295295
///
296-
/// # Example
296+
/// # Examples
297297
/// ```rust
298298
/// # async fn test() {
299299
/// use aws_config::profile::ProfileFileCredentialsProvider;
@@ -310,7 +310,7 @@ impl Builder {
310310

311311
/// Adds a custom credential source
312312
///
313-
/// # Example
313+
/// # Examples
314314
///
315315
/// ```rust
316316
/// use aws_types::credentials::{self, ProvideCredentials, future};

aws/rust-runtime/aws-config/src/profile/credentials/exec.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::web_identity_token::{StaticConfiguration, WebIdentityTokenCredentials
1818
use aws_types::credentials::{self, CredentialsError, ProvideCredentials};
1919
use aws_types::os_shim_internal::Fs;
2020
use smithy_client::erase::DynConnector;
21-
use std::fmt::{Debug, Formatter};
21+
use std::fmt::Debug;
2222

2323
#[derive(Debug)]
2424
pub struct AssumeRoleProvider {
@@ -66,18 +66,12 @@ impl AssumeRoleProvider {
6666
}
6767
}
6868

69+
#[derive(Debug)]
6970
pub(super) struct ProviderChain {
7071
base: Arc<dyn ProvideCredentials>,
7172
chain: Vec<AssumeRoleProvider>,
7273
}
7374

74-
impl Debug for ProviderChain {
75-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
76-
// TODO: ProvideCredentials should probably mandate debug
77-
f.debug_struct("ProviderChain").finish()
78-
}
79-
}
80-
8175
impl ProviderChain {
8276
pub fn base(&self) -> &dyn ProvideCredentials {
8377
self.base.as_ref()

aws/rust-runtime/aws-config/src/profile/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
//! Load configuration from AWS Profiles
77
//!
88
//! AWS profiles are typically stored in `~/.aws/config` and `~/.aws/credentials`. For more details
9-
//! see <todo>
9+
//! see the [`load`](parser::load) function.
1010
1111
mod parser;
12+
#[doc(inline)]
1213
pub use parser::{load, Profile, ProfileSet, Property};
1314

1415
pub mod credentials;
1516
pub mod region;
1617

18+
#[doc(inline)]
1719
pub use credentials::ProfileFileCredentialsProvider;
20+
#[doc(inline)]
1821
pub use region::ProfileFileRegionProvider;

aws/rust-runtime/aws-config/src/profile/parser.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ pub use self::parse::ProfileParseError;
1717

1818
/// Read & parse AWS config files
1919
///
20-
/// Loads and parses profile files according to the spec:
20+
/// Loads AWS config file from the filesystem, parses them, and converts them into a [`ProfileSet`](ProfileSet).
21+
///
22+
/// Although the basic behavior is straightforward, there are number of nuances to maintain backwards
23+
/// compatibility with other SDKs enumerated below.
2124
///
2225
/// ## Location of Profile Files
23-
/// * The location of the config file will be loaded from `$AWS_CONFIG_FILE` with a fallback to
24-
/// `~/.aws/config`
25-
/// * The location of the credentials file will be loaded from `$AWS_SHARED_CREDENTIALS_FILE` with a
26-
/// fallback to `~/.aws/credentials`
26+
/// * The location of the config file will be loaded from the `AWS_CONFIG_FILE` environment variable
27+
/// with a fallback to `~/.aws/config`
28+
/// * The location of the credentials file will be loaded from the `AWS_SHARED_CREDENTIALS_FILE`
29+
/// environment variable with a fallback to `~/.aws/credentials`
2730
///
2831
/// ## Home directory resolution
2932
/// Home directory resolution is implemented to match the behavior of the CLI & Python. `~` is only
@@ -33,15 +36,15 @@ pub use self::parse::ProfileParseError;
3336
/// resolve to the home directory.
3437
///
3538
/// When determining the home directory, the following environment variables are checked:
36-
/// - `$HOME` on all platforms
37-
/// - `$USERPROFILE` on Windows
38-
/// - `$HOMEDRIVE$HOMEPATH` on Windows
39+
/// - `HOME` on all platforms
40+
/// - `USERPROFILE` on Windows
41+
/// - The concatenation of `HOMEDRIVE` and `HOMEPATH` on Windows (`$HOMEDRIVE$HOMEPATH`)
3942
///
4043
/// ## Profile file syntax
4144
///
42-
/// Profile files have a general form similar to INI but with a number of quirks and edge cases. These
43-
/// behaviors are largely to match existing parser implementations and these cases are documented in `test-data/profile-parser-tests.json`
44-
/// in this repo.
45+
/// Profile files have a form similar to `.ini` but with a several edge cases. These behaviors exist
46+
/// to match existing parser implementations, ensuring consistent behavior across AWS SDKs. These
47+
/// cases fully enumerated in `test-data/profile-parser-tests.json`.
4548
///
4649
/// ### The config file `~/.aws/config`
4750
/// ```ini
@@ -76,11 +79,12 @@ pub struct ProfileSet {
7679
}
7780

7881
impl ProfileSet {
82+
#[doc(hidden)]
7983
/// Create a new Profile set directly from a HashMap
8084
///
8185
/// This method creates a ProfileSet directly from a hashmap with no normalization.
8286
///
83-
/// ## Note
87+
/// ## Warning
8488
///
8589
/// This is probably not what you want! In general, [`load`](load) should be used instead
8690
/// because it will perform input normalization. However, for tests which operate on the
@@ -113,7 +117,7 @@ impl ProfileSet {
113117
.and_then(|profile| profile.get(key))
114118
}
115119

116-
/// Retrieve a named profile from the profile set
120+
/// Retrieves a named profile from the profile set
117121
pub fn get_profile(&self, profile_name: &str) -> Option<&Profile> {
118122
self.profiles.get(profile_name)
119123
}
@@ -214,9 +218,9 @@ mod test {
214218
use std::fs;
215219
use tracing_test::traced_test;
216220

217-
/// Run all tests from profile-parser-tests.json
221+
/// Run all tests from `test-data/profile-parser-tests.json`
218222
///
219-
/// These represent the bulk of the test cases and reach effectively 100% coverage
223+
/// These represent the bulk of the test cases and reach 100% coverage of the parser.
220224
#[test]
221225
#[traced_test]
222226
fn run_tests() -> Result<(), Box<dyn Error>> {

aws/rust-runtime/aws-config/src/profile/region.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ use aws_types::region::Region;
1515
/// This provider will attempt to load AWS shared configuration, then read the `region` property
1616
/// from the active profile.
1717
///
18-
/// Example:
18+
/// # Examples
1919
///
20+
/// **Loads "us-west-2" as the region
2021
/// ```ini
21-
/// # `~/.aws/config
2222
/// [default]
2323
/// region = us-west-2
2424
/// ```
2525
///
26-
/// This provider is part of the [default provider chain](crate::default_provider::region).
26+
/// **Loads `us-east-1` as the region _if and only if_ the `AWS_PROFILE` environment variable is set
27+
/// to `other`.
28+
///
29+
/// ```ini
30+
/// [profile other]
31+
/// region = us-east-1
32+
/// ```
33+
///
34+
/// This provider is part of the [default region provider chain](crate::default_provider::region).
2735
#[derive(Debug, Default)]
2836
pub struct ProfileFileRegionProvider {
2937
fs: Fs,

aws/rust-runtime/aws-config/src/provider_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ProviderConfig {
5252
/// a `ProviderConfig` without these fields set, use [`ProviderConfig::empty`].
5353
///
5454
///
55-
/// # Example
55+
/// # Examples
5656
/// ```rust
5757
/// use aws_config::provider_config::ProviderConfig;
5858
/// use aws_sdk_sts::Region;
@@ -80,7 +80,7 @@ impl ProviderConfig {
8080

8181
/// Create a default provider config with the region region automatically loaded from the default chain.
8282
///
83-
/// # Example
83+
/// # Examples
8484
/// ```rust
8585
/// # async fn test() {
8686
/// use aws_config::provider_config::ProviderConfig;

aws/rust-runtime/aws-config/src/web_identity_token.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@
55

66
//! Load Credentials from Web Identity Tokens
77
//!
8-
//! WebIdentity tokens can be loaded via environment variables, or via profiles:
8+
//! Web identity tokens can be loaded from file. The path may be set in one of three ways:
9+
//! 1. [Environment Variables](#environment-variable-configuration)
10+
//! 2. [AWS profile](#aws-profile-configuration) defined in `~/.aws/config`
11+
//! 3. Static configuration via [`static_configuration`](Builder::static_configuration)
912
//!
10-
//! ## Via Environment Variables
13+
//! **Note:** [WebIdentityTokenCredentialsProvider] is part of the [default provider chain](crate::default_provider).
14+
//! Unless you need specific behavior or configuration overrides, it is recommended to use the
15+
//! default chain instead of using this provider directly. This client should be considered a "low level"
16+
//! client as it does not include caching or profile-file resolution when used in isolation.
17+
//!
18+
//! ## Environment Variable Configuration
1119
//! WebIdentityTokenCredentialProvider will load the following environment variables:
1220
//! - `AWS_WEB_IDENTITY_TOKEN_FILE`: **required**, location to find the token file containing a JWT token
1321
//! - `AWS_ROLE_ARN`: **required**, role ARN to assume
1422
//! - `AWS_IAM_ROLE_SESSION_NAME`: **optional**: Session name to use when assuming the role
1523
//!
16-
//! ## Via Shared Config Profiles
24+
//! ## AWS Profile Configuration
25+
//! **Note:** Configuration of the web identity token provider via a shared profile is only supported
26+
//! when using the [`ProfileFileCredentialsProvider`](crate::profile::credentials).
27+
//!
1728
//! Web identity token credentials can be loaded from `~/.aws/config` in two ways:
1829
//! 1. Directly:
1930
//! ```ini
@@ -34,19 +45,21 @@
3445
//! web_identity_token_file = /token.jwt
3546
//! ```
3647
//!
37-
//! # Example
38-
//! Web Identity Token providers are part of the [default chain](crate::default_provider::credentials),
39-
//! however, you can construct one explicitly if you don't want to use the default provider chain:
48+
//! # Examples
49+
//! Web Identity Token providers are part of the [default chain](crate::default_provider::credentials).
50+
//! However, they may be directly constructed if you don't want to use the default provider chain.
51+
//! Unless overridden with [`static_configuration`](Builder::static_configuration), the provider will
52+
//! load configuration from environment variables.
4053
//!
41-
/// ```rust
42-
/// # async fn test() {
43-
/// use aws_config::web_identity_token::WebIdentityTokenCredentialsProvider;
44-
/// use aws_config::provider_config::ProviderConfig;
45-
/// let provider = WebIdentityTokenCredentialsProvider::builder()
46-
/// .configure(&ProviderConfig::with_default_region().await)
47-
/// .build();
48-
/// # }
49-
/// ```
54+
//! ```rust
55+
//! # async fn test() {
56+
//! use aws_config::web_identity_token::WebIdentityTokenCredentialsProvider;
57+
//! use aws_config::provider_config::ProviderConfig;
58+
//! let provider = WebIdentityTokenCredentialsProvider::builder()
59+
//! .configure(&ProviderConfig::with_default_region().await)
60+
//! .build();
61+
//! # }
62+
//! ```
5063
use aws_sdk_sts::Region;
5164
use aws_types::os_shim_internal::{Env, Fs};
5265

@@ -164,7 +177,7 @@ pub struct Builder {
164177
impl Builder {
165178
/// Configure generic options of the [WebIdentityTokenCredentialsProvider]
166179
///
167-
/// # Example
180+
/// # Examples
168181
/// ```rust
169182
/// # async fn test() {
170183
/// use aws_config::web_identity_token::WebIdentityTokenCredentialsProvider;

0 commit comments

Comments
 (0)