Skip to content

Commit c55e961

Browse files
committed
evolve aws_china_mfa – part II
1 parent 8c0d0ce commit c55e961

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

aws_china_mfa/aws_china_mfa.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,29 @@ main() {
158158

159159
set_credentials "$sourced" "$aws_profile" "$access_key" "$secret_key" "$session_token"
160160

161+
echo "" >&2
162+
echo "✓ Successfully authenticated to AWS China" >&2
163+
echo "" >&2
164+
161165
if [[ $sourced -eq 1 ]]; then
162-
echo "" >&2
163-
echo "✓ Successfully authenticated to AWS China" >&2
164-
echo "" >&2
165166
echo "Exported AWS credentials:" >&2
166167
echo "" >&2
167168
env | grep '^AWS_' | sort >&2
168169
else
169-
echo "" >&2
170-
echo "✓ Successfully authenticated to AWS China" >&2
171-
echo "" >&2
172-
echo "Copy and paste the export commands above to apply credentials." >&2
170+
# Execution mode
171+
if [[ -t 1 ]]; then
172+
# stdout is a terminal (not piped to eval)
173+
echo "Copy and paste the export commands above to apply credentials." >&2
174+
else
175+
# stdout is piped (eval mode)
176+
echo "Exported AWS credentials:" >&2
177+
echo "" >&2
178+
echo " AWS_PROFILE=$aws_profile" >&2
179+
echo " AWS_ACCESS_KEY_ID=$access_key" >&2
180+
echo " AWS_SECRET_ACCESS_KEY=$secret_key" >&2
181+
echo " AWS_SESSION_TOKEN=$session_token" >&2
182+
fi
173183
fi
174184
}
175185

176186
main "$@"
177-
178-
# TODO: 1password integration: extract MFA directly from 1Password.

0 commit comments

Comments
 (0)