Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
feat(aws): Support aws-vault as an option instead of named AWS p… (#206)
Browse files Browse the repository at this point in the history
When using [99designs/aws-vault](https://github.com/99designs/aws-vault) the variable `AWS_VAULT` is set to indicate which profile has been configured in the environment and the AWS_PROFILE environment variable is not set. This commits makes AWS_VAULT override the profile name.
  • Loading branch information
kouk authored and matchai committed Aug 21, 2019
1 parent 5f41d61 commit 5e02e3f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Haskell section is shown only in directories that contain `stack.yaml`.

### Amazon Web Services (AWS) (`aws`)

Shows selected Amazon Web Services profile configured using [`AWS_PROFILE`](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html) variable.
Shows selected Amazon Web Services profile configured using [`AWS_VAULT`](https://github.com/99designs/aws-vault) or [`AWS_PROFILE`](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html) variable.

| Variable | Default | Meaning |
| :------- | :-----: | ------- |
Expand Down
17 changes: 13 additions & 4 deletions functions/__sf_section_aws.fish
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ function __sf_section_aws -d "Display the selected aws profile"
# Ensure the aws command is available
type -q aws; or return

# Early return if there's no AWS_PROFILE, or it's set to default
if test -z "$AWS_PROFILE" \
-o "$AWS_PROFILE" = "default"
set -l PROFILE_NAME

# if aws-vault is in use, override profile with that
if test -n "$AWS_VAULT"
set PROFILE_NAME "$AWS_VAULT"
else
set PROFILE_NAME "$AWS_PROFILE"
end

# Early return if there's no named profile, or it's set to default
if test -z "$PROFILE_NAME" \
-o "$PROFILE_NAME" = "default"
return
end

__sf_lib_section \
$SPACEFISH_AWS_COLOR \
$SPACEFISH_AWS_PREFIX \
"$SPACEFISH_AWS_SYMBOL""$AWS_PROFILE" \
"$SPACEFISH_AWS_SYMBOL""$PROFILE_NAME" \
$SPACEFISH_AWS_SUFFIX
end
16 changes: 16 additions & 0 deletions tests/__sf_section_aws.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,19 @@ test "doesn't display the section when SPACEFISH_AWS_SHOW is set to \"false\""
set SPACEFISH_AWS_SHOW false
) = (__sf_section_aws)
end


test "Prints section when AWS_VAULT is set"
(
set AWS_VAULT user2
set_color --bold
echo -n "using "
set_color normal
set_color --bold ff8700
echo -n "☁️ user2"
set_color normal
set_color --bold
echo -n " "
set_color normal
) = (__sf_section_aws)
end

0 comments on commit 5e02e3f

Please sign in to comment.