Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix reading aws credentials #19

Merged
merged 6 commits into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion aws_login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,23 @@ function aws_login() {
get_aws_accounts_from_rackspace
fi

aws_accounts=$(cat "$config_dir/aws_accounts.txt")
# Git Bash does not have pgrep installed
# shellcheck disable=SC2009
if ps -p $$ | grep bash >/dev/null 2>&1; then
aws_accounts=$(cat "$config_dir/aws_accounts.txt")
elif ps -p $$ | grep zsh >/dev/null 2>&1; then
# this is valid ZSH
# shellcheck disable=SC2296
aws_accounts=("${(@f)$(< "$config_dir/aws_accounts.txt")}")
else
echo "Please use bash or zsh."
return 1
fi

if [ -n "$aws_account_no" ]; then
aws_profile_name=""
# false positive because of mixed bash and zsh code
# shellcheck disable=SC2128
for acc in $aws_accounts; do
curr_aws_account_no=$(tr -dc '[:print:]' <<<"$acc" | cut -f 1 -d'_')
if [ "$curr_aws_account_no" = "$aws_account_no" ]; then
Expand All @@ -125,6 +138,8 @@ function aws_login() {
fi
else
PS3='Select the AWS account to connect to: '
# false positive because of mixed bash and zsh code
# shellcheck disable=SC2128
select opt in $aws_accounts; do
aws_account_no=$(tr -dc '[:print:]' <<<"$opt" | cut -f 1 -d'_')
aws_profile_name=$(tr -dc '[:print:]' <<<"$opt" | cut -f 2- -d'_')
Expand Down