feat(aws): Use AWS_VAULT as the profile if set (#984)
* Use AWS_VAULT as the profile if set [aws-vault](https://github.com/99designs/aws-vault) sets the `AWS_VAULT` env var instead of `AWS_PROFILE` when an aws-vault session is active. This PR adds support for reading the AWS profile value from the `AWS_VAULT` env var, giving priority to `AWS_VAULT` if both it and `AWS_PROFILE` are set. * Update docs for AWS_VAULT
This commit is contained in:
parent
7e7ec4e682
commit
9924af55db
|
@ -136,6 +136,9 @@ The `aws` module shows the current AWS region and profile. This is based on
|
||||||
`AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with
|
`AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with
|
||||||
`~/.aws/config` file.
|
`~/.aws/config` file.
|
||||||
|
|
||||||
|
When using [aws-vault](https://github.com/99designs/aws-vault) the profile
|
||||||
|
is read from the `AWS_VAULT` env var.
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Variable | Default | Description |
|
| Variable | Default | Description |
|
||||||
|
|
|
@ -50,7 +50,9 @@ fn get_aws_region_from_config(aws_profile: Option<&str>) -> Option<Region> {
|
||||||
|
|
||||||
fn get_aws_profile_and_region() -> (Option<Profile>, Option<Region>) {
|
fn get_aws_profile_and_region() -> (Option<Profile>, Option<Region>) {
|
||||||
match (
|
match (
|
||||||
env::var("AWS_PROFILE").ok(),
|
env::var("AWS_VAULT")
|
||||||
|
.or_else(|_| env::var("AWS_PROFILE"))
|
||||||
|
.ok(),
|
||||||
env::var("AWS_REGION").ok(),
|
env::var("AWS_REGION").ok(),
|
||||||
env::var("AWS_DEFAULT_REGION").ok(),
|
env::var("AWS_DEFAULT_REGION").ok(),
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -67,6 +67,18 @@ fn profile_set() -> io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn profile_set_from_aws_vault() -> io::Result<()> {
|
||||||
|
let output = common::render_module("aws")
|
||||||
|
.env("AWS_VAULT", "astronauts-vault")
|
||||||
|
.env("AWS_PROFILE", "astronauts-profile")
|
||||||
|
.output()?;
|
||||||
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts-vault"));
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn profile_and_region_set() -> io::Result<()> {
|
fn profile_and_region_set() -> io::Result<()> {
|
||||||
let output = common::render_module("aws")
|
let output = common::render_module("aws")
|
||||||
|
|
Loading…
Reference in New Issue