feat(aws): add support for getting profile from awsu (#2451)
This commit is contained in:
parent
69b9bf72c3
commit
e5cdd9c1b3
|
@ -249,6 +249,9 @@ The `aws` module shows the current AWS region and profile. This is based on
|
||||||
When using [aws-vault](https://github.com/99designs/aws-vault) the profile
|
When using [aws-vault](https://github.com/99designs/aws-vault) the profile
|
||||||
is read from the `AWS_VAULT` env var.
|
is read from the `AWS_VAULT` env var.
|
||||||
|
|
||||||
|
When using [awsu](https://github.com/kreuzwerker/awsu) the profile
|
||||||
|
is read from the `AWSU_PROFILE` env var.
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
|
|
|
@ -47,14 +47,14 @@ fn get_aws_region_from_config(context: &Context, aws_profile: Option<&str>) -> O
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_aws_profile_and_region(context: &Context) -> (Option<Profile>, Option<Region>) {
|
fn get_aws_profile_and_region(context: &Context) -> (Option<Profile>, Option<Region>) {
|
||||||
match (
|
let profile_env_vars = vec!["AWSU_PROFILE", "AWS_VAULT", "AWS_PROFILE"];
|
||||||
context
|
let profile = profile_env_vars
|
||||||
.get_env("AWS_VAULT")
|
.iter()
|
||||||
.or_else(|| context.get_env("AWS_PROFILE")),
|
.find_map(|env_var| context.get_env(env_var));
|
||||||
context
|
let region = context
|
||||||
.get_env("AWS_DEFAULT_REGION")
|
.get_env("AWS_DEFAULT_REGION")
|
||||||
.or_else(|| context.get_env("AWS_REGION")),
|
.or_else(|| context.get_env("AWS_REGION"));
|
||||||
) {
|
match (profile, region) {
|
||||||
(Some(p), Some(r)) => (Some(p), Some(r)),
|
(Some(p), Some(r)) => (Some(p), Some(r)),
|
||||||
(None, Some(r)) => (None, Some(r)),
|
(None, Some(r)) => (None, Some(r)),
|
||||||
(Some(ref p), None) => (
|
(Some(ref p), None) => (
|
||||||
|
@ -200,6 +200,20 @@ mod tests {
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn profile_set_from_awsu() {
|
||||||
|
let actual = ModuleRenderer::new("aws")
|
||||||
|
.env("AWSU_PROFILE", "astronauts-awsu")
|
||||||
|
.env("AWS_PROFILE", "astronauts-profile")
|
||||||
|
.collect();
|
||||||
|
let expected = Some(format!(
|
||||||
|
"on {}",
|
||||||
|
Color::Yellow.bold().paint("☁️ astronauts-awsu ")
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn profile_and_region_set() {
|
fn profile_and_region_set() {
|
||||||
let actual = ModuleRenderer::new("aws")
|
let actual = ModuleRenderer::new("aws")
|
||||||
|
|
Loading…
Reference in New Issue