Created
September 13, 2021 21:40
-
-
Save qrkourier/a1eb24cdb2df5525af0031d8b5b180f4 to your computer and use it in GitHub Desktop.
Source the CSV IAM credential download in BASH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o pipefail -e -u | |
[[ ${#@} -eq 1 && "$1" =~ .csv$ ]] || { | |
echo "ERROR: need a CSV file to convert" >&2 | |
exit 1 | |
} | |
CSV_FILE="$1" | |
[[ -s ${CSV_FILE} ]] || { | |
echo "ERROR: CSV file is empty of missing" >&2 | |
exit 1 | |
} | |
BASH_FILE="${CSV_FILE%.csv}.bash" | |
echo "INFO: writing bash env config in ${BASH_FILE}" | |
cat <<EOF >| ${BASH_FILE} | |
export AWS_ACCESS_KEY_ID="$(while IFS=, read USER_NAME PASSWORD AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY CONSOLE_URL; do [[ ${AWS_ACCESS_KEY_ID} =~ ^[A-Z0-9]{20}$ ]] && echo ${AWS_ACCESS_KEY_ID};done<${CSV_FILE})" | |
export AWS_SECRET_ACCESS_KEY="$(while IFS=, read USER_NAME PASSWORD AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY CONSOLE_URL; do [[ ${AWS_SECRET_ACCESS_KEY} =~ ^[a-zA-Z0-9/+]{40}$ ]] && echo ${AWS_SECRET_ACCESS_KEY};done<${CSV_FILE})" | |
EOF | |
source ${BASH_FILE} | |
if which aws &>/dev/null; then | |
if which jq &>/dev/null; then | |
aws --output json sts get-caller-identity | jq | |
else | |
aws --output text sts get-caller-identity | |
fi | |
else | |
echo "WARN: missing \"aws\" command, unable to verify sourced identity" >&2 | |
fi | |
echo "INFO: You may become this IAM user again in the future by running \"source ${BASH_FILE}\"" |
Author
qrkourier
commented
Sep 13, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment