-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathaws_write_creds.sh
executable file
·39 lines (34 loc) · 1.26 KB
/
aws_write_creds.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
set -o errexit # abort on nonzero exit status
set -o pipefail # don't hide errors within pipes
#
# This script is temporary until we rewrite the AWS deployment following
# 81 and #82. # We look into the environment and if we see environment
# variables for the AWS # authentication process we move them into a
# credentials file. This is primarily being # done at this time to support
# Jenkins using env vars for creds
#
aws_auth_vars=(AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN)
missing_auth_vars=()
for i in "${aws_auth_vars[@]}"; do
test -n "${!i:+y}" || missing_vars+=("$i")
done
if [ ${#missing_auth_vars[@]} -ne 0 ]; then
echo "Did not find values for:"
printf ' %q\n' "${missing_vars[@]}"
echo "Will assume they are in credentials file or not needed"
else
echo "Creating credentials file"
# Create the directory....
mkdir -p ~/.aws
CREDS=~/.aws/credentials
echo "[default]" >$CREDS
echo "aws_access_key_id=$AWS_ACCESS_KEY_ID" >>$CREDS
echo "aws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >>$CREDS
# This is if we have non-temp credentials...
if [[ -z "${AWS_SESSION_TOKEN+x}" ]]; then
echo "Variable AWS_SESSION_TOKEN was unset; not adding to credentials"
else
echo "aws_session_token=$AWS_SESSION_TOKEN" >>$CREDS
fi
fi