diff options
Diffstat (limited to 'plugins/aws')
-rw-r--r-- | plugins/aws/README.md | 8 | ||||
-rw-r--r-- | plugins/aws/aws.plugin.zsh | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 24c6429dd..d6f4f4600 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -16,10 +16,10 @@ plugins=(... aws) Run `asp` without arguments to clear the profile. * `asp [<profile>] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. -* `acp [<profile>]`: in addition to `asp` functionality, it actually changes the profile by - assuming the role specified in the `<profile>` configuration. It supports MFA and sets - `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if obtained. It - requires the roles to be configured as per the +* `acp [<profile>] [<mfa_token>]`: in addition to `asp` functionality, it actually changes + the profile by assuming the role specified in the `<profile>` configuration. It supports + MFA and sets `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if + obtained. It requires the roles to be configured as per the [official guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html). Run `acp` without arguments to clear the profile. diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 3a3a111b4..920a7139d 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -45,6 +45,7 @@ function acp() { fi local profile="$1" + local mfa_token="$2" # Get fallback credentials for if the aws command fails or no command is run local aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)" @@ -58,9 +59,10 @@ function acp() { if [[ -n "$mfa_serial" ]]; then local -a mfa_opt - local mfa_token - echo -n "Please enter your MFA token for $mfa_serial: " - read -r mfa_token + if [[ -z "$mfa_token" ]]; then + echo -n "Please enter your MFA token for $mfa_serial: " + read -r mfa_token + fi if [[ -z "$sess_duration" ]]; then echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): " read -r sess_duration @@ -155,8 +157,8 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { - [[ -z $AWS_PROFILE ]] && return - echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_SUFFIX:=>}" + [[ -n "$AWS_PROFILE" ]] || return + echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE:gs/%/%%}${ZSH_THEME_AWS_SUFFIX:=>}" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then |