From 3d3346be0abbf6cb555feec83a40487c91c637ab Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Sun, 12 Jun 2022 16:22:24 +0200 Subject: [PATCH] [aws] Detect whenever a aws sso login is needed --- modules/aws/init.zsh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/aws/init.zsh b/modules/aws/init.zsh index 4a13f39..f2d7b5d 100644 --- a/modules/aws/init.zsh +++ b/modules/aws/init.zsh @@ -148,6 +148,7 @@ function ssh_aws_any { function aws_switch_profile { local region + local credentials if [[ -z $1 ]]; then echo "Profile can't be an empty string" @@ -166,7 +167,14 @@ function aws_switch_profile { fi if [[ ${_aws_sso} == "true" ]]; then - eval $(aws-export-credentials --env-export) + credentials=$(aws-export-credentials --env-export 2>&1) + + if [[ $credentials =~ "has expired" ]]; then + aws sso login + credentials=$(aws-export-credentials --env-export) + fi + + eval $credentials fi fi }