summaryrefslogtreecommitdiffstats
path: root/src/modules/aws.rs
diff options
context:
space:
mode:
authorkensasongko <ken.sasongko@gmail.com>2023-05-09 12:53:45 +0700
committerGitHub <noreply@github.com>2023-05-09 07:53:45 +0200
commit297176b0b8b9da34176d7b278837f77f960799b1 (patch)
tree8bfa27edd6d9eec531dccf04cd114e6099912810 /src/modules/aws.rs
parent20e251f261d2d08db59e9f081dc5bf5fd036db4f (diff)
feat(aws): support aws sso with automatic authentication refresh (#5170)
* feat(aws): support aws sso with automatic authentication refresh * docs(aws): add sso_session for profile detection
Diffstat (limited to 'src/modules/aws.rs')
-rw-r--r--src/modules/aws.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/modules/aws.rs b/src/modules/aws.rs
index 60fe32894..0d837c2ce 100644
--- a/src/modules/aws.rs
+++ b/src/modules/aws.rs
@@ -174,6 +174,7 @@ fn has_credential_process_or_sso(
Some(
config_section.contains_key("credential_process")
+ || config_section.contains_key("sso_session")
|| config_section.contains_key("sso_start_url")
|| credential_section?.contains_key("credential_process")
|| credential_section?.contains_key("sso_start_url"),
@@ -996,7 +997,7 @@ credential_process = /opt/bin/awscreds-for-tests
}
#[test]
- fn sso_set() -> io::Result<()> {
+ fn sso_legacy_set() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_path = dir.path().join("config");
let mut file = File::create(&config_path)?;
@@ -1027,6 +1028,40 @@ sso_role_name = <AWS-ROLE-NAME>
}
#[test]
+ fn sso_set() -> io::Result<()> {
+ let dir = tempfile::tempdir()?;
+ let config_path = dir.path().join("config");
+ let mut config = File::create(&config_path)?;
+ config.write_all(
+ "[profile astronauts]
+sso_session = my-sso
+sso_account_id = 123456789011
+sso_role_name = readOnly
+region = us-west-2
+output = json
+
+[sso-session my-sso]
+sso_region = us-east-1
+sso_start_url = https://starship.rs/sso
+sso_registration_scopes = sso:account:access
+"
+ .as_bytes(),
+ )?;
+
+ let actual = ModuleRenderer::new("aws")
+ .env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
+ .env("AWS_PROFILE", "astronauts")
+ .collect();
+ let expected = Some(format!(
+ "on {}",
+ Color::Yellow.bold().paint("☁️ astronauts (us-west-2) ")
+ ));
+
+ assert_eq!(expected, actual);
+ dir.close()
+ }
+
+ #[test]
fn access_key_env_var_set() {
let actual = ModuleRenderer::new("aws")
.env("AWS_PROFILE", "astronauts")