Skip to content

Commit 0642b3b

Browse files
Merge feature/credential-features branch to main (#4240)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> Merging the feature branch containing work from the below two PRs: * #4238 * #4224 ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _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: AWS SDK Rust Bot <[email protected]>
1 parent 2229fb1 commit 0642b3b

File tree

27 files changed

+659
-103
lines changed

27 files changed

+659
-103
lines changed

.changelog/credential-features.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
applies_to:
3+
- aws-sdk-rust
4+
authors:
5+
- landonxjames
6+
references:
7+
- smithy-rs#4238
8+
breaking: false
9+
new_feature: true
10+
bug_fix: false
11+
---
12+
Add user-agent feature tracking for credential providers in `aws-config`.

aws/rust-runtime/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-config/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aws/rust-runtime/aws-config/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-config"
3-
version = "1.8.3"
3+
version = "1.8.4"
44
authors = [
55
"AWS Rust SDK Team <[email protected]>",
66
"Russell Cohen <[email protected]>",
@@ -61,8 +61,8 @@ aws-sdk-ssooidc = { path = "../../sdk/build/aws-sdk/sdk/ssooidc", default-featur
6161

6262
[dev-dependencies]
6363
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async", features = ["rt-tokio", "test-util"] }
64-
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"] }
6564
aws-smithy-http-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http-client", features = ["default-client", "test-util"] }
65+
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "test-util"] }
6666
aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"] }
6767
futures-util = { version = "0.3.29", default-features = false }
6868
tracing-test = "0.2.4"

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use crate::json_credentials::{json_parse_loop, InvalidJsonCredentials};
1111
use crate::sensitive_command::CommandWithSensitiveArgs;
1212
use aws_credential_types::attributes::AccountId;
13+
use aws_credential_types::credential_feature::AwsCredentialFeature;
1314
use aws_credential_types::provider::{self, error::CredentialsError, future, ProvideCredentials};
1415
use aws_credential_types::Credentials;
1516
use aws_smithy_json::deserialize::Token;
@@ -122,14 +123,19 @@ impl CredentialProcessProvider {
122123
))
123124
})?;
124125

125-
parse_credential_process_json_credentials(output, self.profile_account_id.as_ref()).map_err(
126-
|invalid| {
126+
parse_credential_process_json_credentials(output, self.profile_account_id.as_ref())
127+
.map(|mut creds| {
128+
creds
129+
.get_property_mut_or_default::<Vec<AwsCredentialFeature>>()
130+
.push(AwsCredentialFeature::CredentialsProcess);
131+
creds
132+
})
133+
.map_err(|invalid| {
127134
CredentialsError::provider_error(format!(
128135
"Error retrieving credentials from external process, could not parse response: {}",
129136
invalid
130137
))
131-
},
132-
)
138+
})
133139
}
134140
}
135141

@@ -264,6 +270,7 @@ fn parse_expiration(expiration: impl AsRef<str>) -> Result<SystemTime, InvalidJs
264270
mod test {
265271
use crate::credential_process::CredentialProcessProvider;
266272
use crate::sensitive_command::CommandWithSensitiveArgs;
273+
use aws_credential_types::credential_feature::AwsCredentialFeature;
267274
use aws_credential_types::provider::ProvideCredentials;
268275
use std::time::{Duration, SystemTime};
269276
use time::format_description::well_known::Rfc3339;
@@ -339,4 +346,19 @@ mod test {
339346
let creds = provider.provide_credentials().await.unwrap();
340347
assert_eq!("111122223333", creds.account_id().unwrap().as_str());
341348
}
349+
350+
#[tokio::test]
351+
async fn credential_feature() {
352+
let provider = CredentialProcessProvider::builder()
353+
.command(CommandWithSensitiveArgs::new(String::from(
354+
r#"echo '{ "Version": 1, "AccessKeyId": "ASIARTESTID", "SecretAccessKey": "TESTSECRETKEY", "AccountId": "111122223333" }'"#,
355+
)))
356+
.account_id("012345678901")
357+
.build();
358+
let creds = provider.provide_credentials().await.unwrap();
359+
assert_eq!(
360+
&vec![AwsCredentialFeature::CredentialsProcess],
361+
creds.get_property::<Vec<AwsCredentialFeature>>().unwrap()
362+
);
363+
}
342364
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use std::env::VarError;
77

88
use aws_credential_types::attributes::AccountId;
9+
use aws_credential_types::credential_feature::AwsCredentialFeature;
910
use aws_credential_types::provider::{self, error::CredentialsError, future, ProvideCredentials};
1011
use aws_credential_types::Credentials;
1112
use aws_types::os_shim_internal::Env;
@@ -58,7 +59,11 @@ impl EnvironmentVariableCredentialsProvider {
5859
.provider_name(ENV_PROVIDER);
5960
builder.set_session_token(session_token);
6061
builder.set_account_id(account_id);
61-
Ok(builder.build())
62+
let mut creds = builder.build();
63+
creds
64+
.get_property_mut_or_default::<Vec<AwsCredentialFeature>>()
65+
.push(AwsCredentialFeature::CredentialsEnvVars);
66+
Ok(creds)
6267
}
6368
}
6469

@@ -110,6 +115,7 @@ fn err_if_blank(value: String) -> Result<String, VarError> {
110115

111116
#[cfg(test)]
112117
mod test {
118+
use aws_credential_types::credential_feature::AwsCredentialFeature;
113119
use aws_credential_types::provider::{error::CredentialsError, ProvideCredentials};
114120
use aws_types::os_shim_internal::Env;
115121
use futures_util::FutureExt;
@@ -250,6 +256,26 @@ mod test {
250256
}
251257
}
252258

259+
#[test]
260+
fn credentials_feature() {
261+
let provider = make_provider(&[
262+
("AWS_ACCESS_KEY_ID", "access"),
263+
("AWS_SECRET_ACCESS_KEY", "secret"),
264+
("SECRET_ACCESS_KEY", "secret"),
265+
("AWS_SESSION_TOKEN", "token"),
266+
]);
267+
268+
let creds = provider
269+
.provide_credentials()
270+
.now_or_never()
271+
.unwrap()
272+
.expect("valid credentials");
273+
assert_eq!(
274+
&vec![AwsCredentialFeature::CredentialsEnvVars],
275+
creds.get_property::<Vec<AwsCredentialFeature>>().unwrap()
276+
);
277+
}
278+
253279
#[test]
254280
fn real_environment() {
255281
let provider = EnvironmentVariableCredentialsProvider::new();

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use crate::json_credentials::{parse_json_credentials, JsonCredentials, RefreshableCredentials};
1212
use crate::provider_config::ProviderConfig;
1313
use aws_credential_types::attributes::AccountId;
14+
use aws_credential_types::credential_feature::AwsCredentialFeature;
1415
use aws_credential_types::provider::{self, error::CredentialsError};
1516
use aws_credential_types::Credentials;
1617
use aws_smithy_runtime::client::metrics::MetricsRuntimePlugin;
@@ -54,7 +55,16 @@ impl HttpCredentialProvider {
5455
}
5556

5657
pub(crate) async fn credentials(&self, auth: Option<HeaderValue>) -> provider::Result {
57-
let credentials = self.operation.invoke(HttpProviderAuth { auth }).await;
58+
let credentials =
59+
self.operation
60+
.invoke(HttpProviderAuth { auth })
61+
.await
62+
.map(|mut creds| {
63+
creds
64+
.get_property_mut_or_default::<Vec<AwsCredentialFeature>>()
65+
.push(AwsCredentialFeature::CredentialsHttp);
66+
creds
67+
});
5868
match credentials {
5969
Ok(creds) => Ok(creds),
6070
Err(SdkError::ServiceError(context)) => Err(context.into_err()),
@@ -233,6 +243,7 @@ impl ClassifyRetry for HttpCredentialRetryClassifier {
233243
#[cfg(test)]
234244
mod test {
235245
use super::*;
246+
use aws_credential_types::credential_feature::AwsCredentialFeature;
236247
use aws_credential_types::provider::error::CredentialsError;
237248
use aws_smithy_http_client::test_util::{ReplayEvent, StaticReplayClient};
238249
use aws_smithy_types::body::SdkBody;
@@ -346,4 +357,14 @@ mod test {
346357
);
347358
http_client.assert_requests_match(&[]);
348359
}
360+
361+
#[tokio::test]
362+
async fn credentials_feature() {
363+
let http_client = StaticReplayClient::new(vec![successful_req_resp()]);
364+
let creds = provide_creds(http_client.clone()).await.expect("success");
365+
assert_eq!(
366+
&vec![AwsCredentialFeature::CredentialsHttp],
367+
creds.get_property::<Vec<AwsCredentialFeature>>().unwrap()
368+
);
369+
}
349370
}

aws/rust-runtime/aws-config/src/imds/client.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,8 @@ pub(crate) mod test {
652652
use aws_smithy_runtime_api::client::interceptors::context::{
653653
Input, InterceptorContext, Output,
654654
};
655-
use aws_smithy_runtime_api::client::orchestrator::{
656-
HttpRequest, HttpResponse, OrchestratorError,
657-
};
655+
use aws_smithy_runtime_api::client::orchestrator::OrchestratorError;
656+
use aws_smithy_runtime_api::client::orchestrator::{HttpRequest, HttpResponse};
658657
use aws_smithy_runtime_api::client::result::ConnectorError;
659658
use aws_smithy_runtime_api::client::retries::classifiers::{
660659
ClassifyRetry, RetryAction, SharedRetryClassifier,
@@ -690,6 +689,7 @@ pub(crate) mod test {
690689
const TOKEN_A: &str = "AQAEAFTNrA4eEGx0AQgJ1arIq_Cc-t4tWt3fB0Hd8RKhXlKc5ccvhg==";
691690
const TOKEN_B: &str = "alternatetoken==";
692691

692+
/// Create a simple token request
693693
pub(crate) fn token_request(base: &str, ttl: u32) -> HttpRequest {
694694
http::Request::builder()
695695
.uri(format!("{}/latest/api/token", base))
@@ -701,6 +701,7 @@ pub(crate) mod test {
701701
.unwrap()
702702
}
703703

704+
/// Create a simple token response
704705
pub(crate) fn token_response(ttl: u32, token: &'static str) -> HttpResponse {
705706
HttpResponse::try_from(
706707
http::Response::builder()
@@ -712,6 +713,7 @@ pub(crate) mod test {
712713
.unwrap()
713714
}
714715

716+
/// Create a simple IMDS request
715717
pub(crate) fn imds_request(path: &'static str, token: &str) -> HttpRequest {
716718
http::Request::builder()
717719
.uri(Uri::from_static(path))
@@ -723,6 +725,7 @@ pub(crate) mod test {
723725
.unwrap()
724726
}
725727

728+
/// Create a simple IMDS response
726729
pub(crate) fn imds_response(body: &'static str) -> HttpResponse {
727730
HttpResponse::try_from(
728731
http::Response::builder()
@@ -733,6 +736,7 @@ pub(crate) mod test {
733736
.unwrap()
734737
}
735738

739+
/// Create an IMDS client with an underlying [StaticReplayClient]
736740
pub(crate) fn make_imds_client(http_client: &StaticReplayClient) -> super::Client {
737741
tokio::time::pause();
738742
super::Client::builder()

0 commit comments

Comments
 (0)