mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 13:47:38 +00:00
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:
parent
538329d9b4
commit
e04f126a10
@ -274,7 +274,9 @@ format = "$all$directory$character"
|
||||
## AWS
|
||||
|
||||
The `aws` module shows the current AWS region and profile when
|
||||
credentials, a `credential_process` or a `sso_start_url` have been setup. This is based on
|
||||
credentials, a `credential_process` or a `sso_start_url` have been setup. Alternatively, you can force this
|
||||
module to show the region and profile event when the credentials have not been setup
|
||||
with the `force_display` option. This is based on
|
||||
`AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with
|
||||
`~/.aws/config` file. This module also shows an expiration timer when using temporary
|
||||
credentials.
|
||||
@ -284,6 +286,8 @@ The module will display a profile only if its credentials are present in
|
||||
`~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`,
|
||||
`AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will
|
||||
also suffice.
|
||||
If the option `force_display` is set to `true`, all available information will be
|
||||
displayed even if the conditions above are not respected.
|
||||
|
||||
When using [aws-vault](https://github.com/99designs/aws-vault) the profile
|
||||
is read from the `AWS_VAULT` env var and the credentials expiration date
|
||||
@ -298,15 +302,16 @@ date is read from the `AWSUME_EXPIRATION` env var.
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------------- |
|
||||
| `format` | `'on [$symbol($profile )(\($region\) )(\[$duration\])]($style)'` | The format for the module. |
|
||||
| `symbol` | `"☁️ "` | The symbol used before displaying the current AWS profile. |
|
||||
| `region_aliases` | | Table of region aliases to display in addition to the AWS name. |
|
||||
| `profile_aliases` | | Table of profile aliases to display in addition to the AWS name. |
|
||||
| `style` | `"bold yellow"` | The style for the module. |
|
||||
| `expiration_symbol` | `X` | The symbol displayed when the temporary credentials have expired. |
|
||||
| `disabled` | `false` | Disables the `AWS` module. |
|
||||
| Option | Default | Description |
|
||||
| ------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
||||
| `format` | `'on [$symbol($profile )(\($region\) )(\[$duration\])]($style)'` | The format for the module. |
|
||||
| `symbol` | `"☁️ "` | The symbol used before displaying the current AWS profile. |
|
||||
| `region_aliases` | | Table of region aliases to display in addition to the AWS name. |
|
||||
| `profile_aliases` | | Table of profile aliases to display in addition to the AWS name. |
|
||||
| `style` | `"bold yellow"` | The style for the module. |
|
||||
| `expiration_symbol` | `X` | The symbol displayed when the temporary credentials have expired. |
|
||||
| `disabled` | `false` | Disables the `AWS` module. |
|
||||
| `force_display` | `false` | If true displays info even if `credentials`, `credential_process` or `sso_start_url` have not been setup. |
|
||||
|
||||
### Variables
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()?;
|
||||
|
Loading…
Reference in New Issue
Block a user