Skip to content

Commit

Permalink
#17 - Write aws config file to a temporary directory (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeyers99 committed Aug 19, 2021
1 parent 12ba236 commit 2f8a4ff
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ set -u
set -o pipefail

awsDir="${HOME}/.aws"
config="${awsDir}/config"
config="$(mktemp)"
credentials="${awsDir}/credentials"

# Delete the temporary file when this script finishes running, is interrupted, or exits abnormally
trap "rm -f $config" 0 2 3 15

mkdir -p "${awsDir}"
echo -e "[profile default]\noutput = json" >>"$config"
echo -e "[profile default]\noutput = json" >"$config"

# Attempt to get aws credentials via tokendito
max_attempts=10
totp_time=30
totp_error='Each code can only be used once. Please wait for a new code and try again.'
for ((attempts = 1; attempts <= $max_attempts; attempts++)); do
echo "Requesting AWS credentials via Tokendito."
t_error=$(tokendito --aws-profile default -ou $INPUT_OKTA_APP_URL -R $INPUT_AWS_ROLE_ARN --username $INPUT_OKTA_USERNAME --password $INPUT_OKTA_PASSWORD --mfa-method ${INPUT_OKTA_MFA_METHOD:=token:software:totp} --mfa-response $(echo $INPUT_OKTA_MFA_SEED | mintotp ${totp_time}) 2>&1 1>/dev/null)
t_error=$(tokendito --config-file $config --aws-profile default -ou $INPUT_OKTA_APP_URL -R $INPUT_AWS_ROLE_ARN --username $INPUT_OKTA_USERNAME --password $INPUT_OKTA_PASSWORD --mfa-method ${INPUT_OKTA_MFA_METHOD:=token:software:totp} --mfa-response $(echo $INPUT_OKTA_MFA_SEED | mintotp ${totp_time}) 2>&1 1>/dev/null)

if [[ $? == 0 ]]; then
echo "Succeeded getting credentials in attempt #${attempts}."
Expand Down

0 comments on commit 2f8a4ff

Please sign in to comment.