diff options
author | Maksym <maksyms@users.noreply.github.com> | 2020-10-29 21:13:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-29 22:13:36 +0100 |
commit | 852a44094a3bb4df39f8f778bc7ada2ddda09727 (patch) | |
tree | 89c37c3832477f0c72debb79283c160e91b728cc /plugins/aws/aws.plugin.zsh | |
parent | 39c79493feb71da4ba3b69eb82229804b27209cc (diff) | |
download | zsh-852a44094a3bb4df39f8f778bc7ada2ddda09727.tar.gz zsh-852a44094a3bb4df39f8f778bc7ada2ddda09727.tar.bz2 zsh-852a44094a3bb4df39f8f778bc7ada2ddda09727.zip |
aws: split setting profile from changing profile (#9402)
the change to assume a role when it is specified in configuration broke some workflows. This fix addresses that
Fixes #9394
Diffstat (limited to 'plugins/aws/aws.plugin.zsh')
-rw-r--r-- | plugins/aws/aws.plugin.zsh | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index fe1f098e8..8149ba121 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -5,6 +5,27 @@ function agp() { # AWS profile selection function asp() { if [[ -z "$1" ]]; then + unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE + echo AWS profile cleared. + return + fi + + local -a available_profiles + available_profiles=($(aws_profiles)) + if [[ -z "${available_profiles[(r)$1]}" ]]; then + echo "${fg[red]}Profile '$1' not found in '${AWS_CONFIG_FILE:-$HOME/.aws/config}'" >&2 + echo "Available profiles: ${(j:, :)available_profiles:-no profiles found}${reset_color}" >&2 + return 1 + fi + + export AWS_DEFAULT_PROFILE=$1 + export AWS_PROFILE=$1 + export AWS_EB_PROFILE=$1 +} + +# AWS profile switch +function acp() { + if [[ -z "$1" ]]; then unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN echo AWS profile cleared. return @@ -34,7 +55,7 @@ function asp() { echo "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role):" read sess_duration if [[ -z $sess_duration ]]; then - sess_duration = 3600 + sess_duration="3600" fi mfa_opt="--serial-number $mfa_serial --token-code $mfa_token --duration-seconds $sess_duration" fi @@ -100,6 +121,7 @@ function _aws_profiles() { reply=($(aws_profiles)) } compctl -K _aws_profiles asp aws_change_access_key +compctl -K _aws_profiles acp aws_change_access_key # AWS prompt function aws_prompt_info() { |