summaryrefslogtreecommitdiff
path: root/plugins/aws/aws.plugin.zsh
diff options
context:
space:
mode:
authorMark Keisler <mark@mitsein.net>2023-04-18 03:36:07 -0500
committerGitHub <noreply@github.com>2023-04-18 10:36:07 +0200
commit673b9fc3317d48a169fe612575186b3eb1a42a13 (patch)
treec933f364a209e6f5556faaed2fb02cd7b3d2ebd9 /plugins/aws/aws.plugin.zsh
parentd889eca72633b7a66d6c832736a5460c5f1a1833 (diff)
downloadzsh-673b9fc3317d48a169fe612575186b3eb1a42a13.tar.gz
zsh-673b9fc3317d48a169fe612575186b3eb1a42a13.tar.bz2
zsh-673b9fc3317d48a169fe612575186b3eb1a42a13.zip
feat(aws)!: improve `aws_change_access_key` (#11378)
BREAKING CHANGE: This commit removes compatibility for `aws` cli v1. Now only v2 is supported.
Diffstat (limited to 'plugins/aws/aws.plugin.zsh')
-rw-r--r--plugins/aws/aws.plugin.zsh37
1 files changed, 31 insertions, 6 deletions
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() {