feat(aws): add option to force AWS display (#3720)

* add option to force AWS display

Even if no credentials or credential_process have been setup

* change README wording

* Include sso_start_url in the description

* Change option name to force_display
This commit is contained in:
Alex Douze
2022-03-25 22:30:36 +01:00
committed by GitHub
parent 538329d9b4
commit e04f126a10
3 changed files with 49 additions and 11 deletions
+2
View File
@@ -12,6 +12,7 @@ pub struct AwsConfig<'a> {
pub region_aliases: HashMap<String, &'a str>,
pub profile_aliases: HashMap<String, &'a str>,
pub expiration_symbol: &'a str,
pub force_display: bool,
}
impl<'a> Default for AwsConfig<'a> {
@@ -24,6 +25,7 @@ impl<'a> Default for AwsConfig<'a> {
region_aliases: HashMap::new(),
profile_aliases: HashMap::new(),
expiration_symbol: "X",
force_display: false,
}
}
}
+32 -1
View File
@@ -186,7 +186,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
// only display if credential_process is defined or has valid credentials
if !has_credential_process_or_sso(context, aws_profile.as_ref())
if !config.force_display
&& !has_credential_process_or_sso(context, aws_profile.as_ref())
&& get_defined_credentials(context, aws_profile.as_ref()).is_none()
{
return None;
@@ -787,6 +788,36 @@ region = us-east-2
dir.close()
}
#[test]
fn missing_any_credentials_but_display_empty() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_path = dir.path().join("config");
let mut file = File::create(&config_path)?;
file.write_all(
"[profile astronauts]
region = us-east-2
"
.as_bytes(),
)?;
let actual = ModuleRenderer::new("aws")
.config(toml::toml! {
[aws]
force_display = true
})
.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-east-2) ")
));
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn access_key_credential_set() -> io::Result<()> {
let dir = tempfile::tempdir()?;