From 4a39779067eda369152bfd6b653f843286c930c0 Mon Sep 17 00:00:00 2001 From: Yu Xiang Zhang Date: Tue, 14 Mar 2023 19:02:54 +0000 Subject: feat(aws): set region when AWS_REGION is not set --- plugins/aws/README.md | 2 +- plugins/aws/aws.plugin.zsh | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'plugins/aws') diff --git a/plugins/aws/README.md b/plugins/aws/README.md index e1e355741..846bf1414 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -12,7 +12,7 @@ plugins=(... aws) ## Plugin commands * `asp []`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to ``. - It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. + It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. Run `asp` without arguments to clear the profile. * `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 1c386a3e1..39c47d572 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -9,7 +9,7 @@ function agr() { # AWS profile selection function asp() { if [[ -z "$1" ]]; then - unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE + unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION echo AWS profile cleared. return fi @@ -26,6 +26,8 @@ function asp() { export AWS_PROFILE=$1 export AWS_EB_PROFILE=$1 + export AWS_PROFILE_REGION=$(aws configure get region) + if [[ "$2" == "login" ]]; then aws sso login fi @@ -195,7 +197,8 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} + echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then -- cgit v1.2.3-70-g09d2 From f9f01e48a890ad4359a6973d1b8a7039f57b2d08 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 21 Mar 2023 15:29:48 +0100 Subject: fix(aws): do not print region if it's not defined Closes #11568 Closes #11570 --- plugins/aws/aws.plugin.zsh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'plugins/aws') diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 39c47d572..0242be97e 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -196,9 +196,15 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { - if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + local _aws_to_show + if [[ -n $AWS_PROFILE ]];then + _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" + fi + if [[ -n $AWS_REGION ]]; then + [[ -n $AWS_PROFILE ]] && _aws_to_show+=" " + _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=}" + fi + echo "$_aws_to_show" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then -- cgit v1.2.3-70-g09d2 From fcbdc330ff50617c8b84d39ce069cc75df41108f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 28 Mar 2023 16:55:53 +0200 Subject: fix(aws): restore accidentally deleted variable Closes #11589 --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/aws') diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0242be97e..a379eaa18 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -197,6 +197,7 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { local _aws_to_show + local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" if [[ -n $AWS_PROFILE ]];then _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" fi @@ -211,7 +212,6 @@ if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; th RPROMPT='$(aws_prompt_info)'"$RPROMPT" fi - # Load awscli completions # AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back -- cgit v1.2.3-70-g09d2 From 673b9fc3317d48a169fe612575186b3eb1a42a13 Mon Sep 17 00:00:00 2001 From: Mark Keisler Date: Tue, 18 Apr 2023 03:36:07 -0500 Subject: feat(aws)!: improve `aws_change_access_key` (#11378) BREAKING CHANGE: This commit removes compatibility for `aws` cli v1. Now only v2 is supported. --- plugins/aws/README.md | 11 ++++++----- plugins/aws/aws.plugin.zsh | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'plugins/aws') diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 846bf1414..54bc7a44d 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -1,7 +1,8 @@ # aws -This plugin provides completion support for [awscli](https://docs.aws.amazon.com/cli/latest/reference/index.html) +This plugin provides completion support for [awscli v2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html) and a few utilities to manage AWS profiles/regions and display them in the prompt. +[awscli v1](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html) is no longer supported. To use it, add `aws` to the plugins array in your zshrc file. @@ -12,9 +13,9 @@ plugins=(... aws) ## Plugin commands * `asp []`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to ``. - It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. + It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. Run `asp` without arguments to clear the profile. -* `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. +* `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. * `asr []`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to ``. Run `asr` without arguments to clear the profile. @@ -65,7 +66,7 @@ the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control Source profile credentials in `~/.aws/credentials`: -``` +```ini [source-profile-name] aws_access_key_id = ... aws_secret_access_key = ... @@ -73,7 +74,7 @@ aws_secret_access_key = ... Role configuration in `~/.aws/config`: -``` +```ini [profile source-profile-name] mfa_serial = arn:aws:iam::111111111111:mfa/myuser region = us-east-1 diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index a379eaa18..d45abba57 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -160,14 +160,39 @@ function aws_change_access_key() { return 1 fi - echo "Insert the credentials when asked." - asp "$1" || return 1 - AWS_PAGER="" aws iam create-access-key - AWS_PAGER="" aws configure --profile "$1" + local profile="$1" + # Get current access key + local original_aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)" + + asp "$profile" || return 1 + echo "Generating a new access key pair for you now." + if aws --no-cli-pager iam create-access-key; then + echo "Insert the newly generated credentials when asked." + aws --no-cli-pager configure --profile $profile + else + echo "Current access keys:" + aws --no-cli-pager iam list-access-keys + echo "Profile \"${profile}\" is currently using the $original_aws_access_key_id key. You can delete an old access key by running \`aws --profile $profile iam delete-access-key --access-key-id AccessKeyId\`" + return 1 + fi - echo "You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`" + read -q "yn?Would you like to disable your previous access key (${original_aws_access_key_id}) now? " + case $yn in + [Yy]*) + echo -n "\nDisabling access key ${original_aws_access_key_id}..." + if aws --no-cli-pager update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then + echo "done." + else + echo "\nFailed to disable ${original_aws_access_key_id} key." + fi + ;; + *) + echo "" + ;; + esac + echo "You can now safely delete the old access key by running \`aws --profile $profile iam delete-access-key --access-key-id ${original_aws_access_key_id}\`" echo "Your current keys are:" - AWS_PAGER="" aws iam list-access-keys + aws --no-cli-pager iam list-access-keys } function aws_regions() { -- cgit v1.2.3-70-g09d2 From 9139d30ca30f8f687cc21121ed9b4f5238bc5260 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Wed, 19 Apr 2023 22:46:10 +0900 Subject: feat(aws): allow more customisation in prompt function (#11619) --- plugins/aws/README.md | 2 ++ plugins/aws/aws.plugin.zsh | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'plugins/aws') diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 54bc7a44d..9e1e055b8 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -58,6 +58,8 @@ the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control * ZSH_THEME_AWS_REGION_SUFFIX: sets the suffix of the AWS_REGION. Defaults to `>`. +* ZSH_THEME_AWS_DIVIDER: sets the divider between ZSH_THEME_AWS_PROFILE_SUFFIX and ZSH_THEME_AWS_REGION_PREFIX. Defaults to ` ` (single space). + ## Configuration [Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) by AWS diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index d45abba57..0da91bc22 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -223,13 +223,16 @@ compctl -K _aws_profiles asp acp aws_change_access_key function aws_prompt_info() { local _aws_to_show local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" + if [[ -n $AWS_PROFILE ]];then - _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" + _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX=""}" fi + if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+=" " - _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=}" + [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=' '}" + _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi + echo "$_aws_to_show" } -- cgit v1.2.3-70-g09d2 From 343c78ae91ff03ea66517b1d69b25fa262ce5408 Mon Sep 17 00:00:00 2001 From: Idan Fishman Date: Thu, 27 Apr 2023 11:49:26 +0200 Subject: fix(aws): set properly set divider to space Closes #11649 Co-authored-by: Carlo Sala --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/aws') diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0da91bc22..a437dc8e8 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -229,7 +229,7 @@ function aws_prompt_info() { fi if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=' '}" + [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi -- cgit v1.2.3-70-g09d2 From 017e288560ef7bdfb8835516d6b3b77bbdcdde6c Mon Sep 17 00:00:00 2001 From: Mark Keisler Date: Sat, 6 May 2023 06:40:06 -0500 Subject: fix(aws): correct access key disable command (#11671) --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/aws') diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index a437dc8e8..b2415b737 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -180,7 +180,7 @@ function aws_change_access_key() { case $yn in [Yy]*) echo -n "\nDisabling access key ${original_aws_access_key_id}..." - if aws --no-cli-pager update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then + if aws --no-cli-pager iam update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then echo "done." else echo "\nFailed to disable ${original_aws_access_key_id} key." -- cgit v1.2.3-70-g09d2 From f01eea76da194fef6005f53a281b6f5a998db126 Mon Sep 17 00:00:00 2001 From: ZYX Date: Fri, 12 May 2023 02:42:30 -0700 Subject: fix(aws): use the correct variable to assert region is defined (#11691) --- plugins/aws/aws.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/aws') diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index b2415b737..c946515be 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -224,12 +224,12 @@ function aws_prompt_info() { local _aws_to_show local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" - if [[ -n $AWS_PROFILE ]];then + if [[ -n "$AWS_PROFILE" ]];then _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX=""}" fi - if [[ -n $AWS_REGION ]]; then - [[ -n $AWS_PROFILE ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" + if [[ -n "$region" ]]; then + [[ -n "$_aws_to_show" ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}" _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX=""}" fi -- cgit v1.2.3-70-g09d2