Skip to content

Commit

Permalink
Fix the error message for SSO credential providers
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed May 23, 2023
1 parent c0345a5 commit d7328b0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ message = "Fix compiler errors in generated code when naming shapes after types
references = ["smithy-rs#2696"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "jdisanti"

[[aws-sdk-rust]]
message = "Fix error message when `credentials-sso` feature is not enabled on `aws-config`. NOTE: if you use `no-default-features`, you will need to manually able `credentials-sso` after 0.55.*"
references = ["smithy-rs#2722", "aws-sdk-rust#703"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"
25 changes: 16 additions & 9 deletions aws/rust-runtime/aws-config/src/default_provider/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,23 @@ mod test {
/// make_test!(live: test_name)
/// ```
macro_rules! make_test {
($name: ident) => {
make_test!($name, execute);
($name: ident $(#[$m:meta])*) => {
make_test!($name, execute, $(#[$m])*);
};
(update: $name:ident) => {
make_test!($name, execute_and_update);
};
(live: $name:ident) => {
make_test!($name, execute_from_live_traffic);
};
($name: ident, $func: ident) => {
make_test!($name, $func, std::convert::identity);
($name: ident, $func: ident, $(#[$m:meta])*) => {
make_test!($name, $func, std::convert::identity $(, #[$m])*);
};
($name: ident, $provider_config_builder: expr) => {
($name: ident, builder: $provider_config_builder: expr) => {
make_test!($name, execute, $provider_config_builder);
};
($name: ident, $func: ident, $provider_config_builder: expr) => {
($name: ident, $func: ident, $provider_config_builder: expr $(, #[$m:meta])*) => {
$(#[$m])*
#[tokio::test]
async fn $name() {
crate::test_case::TestEnvironment::from_dir(concat!(
Expand Down Expand Up @@ -274,19 +275,19 @@ mod test {

make_test!(imds_no_iam_role);
make_test!(imds_default_chain_error);
make_test!(imds_default_chain_success, |config| {
make_test!(imds_default_chain_success, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
});
make_test!(imds_assume_role);
make_test!(imds_config_with_no_creds, |config| {
make_test!(imds_config_with_no_creds, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
});
make_test!(imds_disabled);
make_test!(imds_default_chain_retries, |config| {
make_test!(imds_default_chain_retries, builder: |config| {
config.with_time_source(aws_credential_types::time_source::TimeSource::testing(
&aws_credential_types::time_source::TestingTimeSource::new(std::time::UNIX_EPOCH),
))
Expand All @@ -295,8 +296,14 @@ mod test {
make_test!(ecs_credentials);
make_test!(ecs_credentials_invalid_profile);

#[cfg(not(feature = "credentials-sso"))]
make_test!(sso_assume_role #[should_panic(expected = "This behavior requires following cargo feature(s) enabled: credentials-sso")]);
#[cfg(not(feature = "credentials-sso"))]
make_test!(sso_no_token_file #[should_panic(expected = "This behavior requires following cargo feature(s) enabled: credentials-sso")]);

#[cfg(feature = "credentials-sso")]
make_test!(sso_assume_role);

#[cfg(feature = "credentials-sso")]
make_test!(sso_no_token_file);

Expand Down
13 changes: 13 additions & 0 deletions aws/rust-runtime/aws-config/src/profile/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ pub enum ProfileFileError {
/// The name of the provider
name: String,
},

/// Feature not enabled
#[non_exhaustive]
FeatureNotEnabled {
/// The feature or comma delimited list of features that must be enabled
feature: Cow<'static, str>,
},
}

impl ProfileFileError {
Expand Down Expand Up @@ -309,6 +316,12 @@ impl Display for ProfileFileError {
"profile `{}` did not contain credential information",
profile
),
ProfileFileError::FeatureNotEnabled { feature: message } => {
write!(
f,
"This behavior requires following cargo feature(s) enabled: {message}",
)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-config/src/profile/credentials/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ impl ProviderChain {
}
#[cfg(not(feature = "credentials-sso"))]
{
Err(ProfileFileError::UnknownProvider {
name: "sso".to_string(),
Err(ProfileFileError::FeatureNotEnabled {
feature: "credentials-sso".into(),
})?
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
);
}
(Err(actual_error), GenericTestResult::Ok(expected_creds)) => panic!(
"expected credentials ({:?}) but an error was returned: {}",
"expected credentials ({:?}) but an error was returned: {:?}",
expected_creds, actual_error
),
(Ok(creds), GenericTestResult::ErrorContains(substr)) => panic!(
Expand Down

0 comments on commit d7328b0

Please sign in to comment.