Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7f0642

Browse files
Gunasekar KGunasekar K
Gunasekar K
authored and
Gunasekar K
committedFeb 8, 2019
aws configuration dynamic
1 parent 6bb4e35 commit c7f0642

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎awsconfiguration.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
AWSENV=$1
3+
BASE64_DECODER="base64 -d" # option -d for Linux base64 tool
4+
echo AAAA | base64 -d > /dev/null 2>&1 || BASE64_DECODER="base64 -D" # option -D on MacOS
5+
decode_base64_url() {
6+
local len=$((${#1} % 4))
7+
local result="$1"
8+
if [ $len -eq 2 ]; then result="$1"'=='
9+
elif [ $len -eq 3 ]; then result="$1"'='
10+
fi
11+
echo "$result" | tr '_-' '/+' | $BASE64_DECODER
12+
}
13+
14+
auth0cmd=$(echo "curl -X POST $CI_AUTH0_URL -H 'Content-Type: application/json' -d '{ \"client_id\": \"$CI_AUTH0_CLIENTID\", \"client_secret\": \"$CI_AUTH0_CLIENTSECRET\", \"audience\": \"$CI_AUTH0_AUDIENCE\", \"grant_type\": \"client_credentials\" , \"environment\" : \"$AWSENV\" , \"username\" : \"$CIRCLE_PROJECT_USERNAME\" , \"reponame\" : \"$CIRCLE_PROJECT_REPONAME\", \"build_num\": \"$CIRCLE_BUILD_NUM\", \"branch\": \"$CIRCLE_BRANCH\"}'")
15+
token=$( eval $auth0cmd | jq -r .access_token )
16+
tokenjsonformat=$( decode_base64_url $(echo -n $token | cut -d "." -f 2) )
17+
AWS_ACCESS_KEY=$(echo $tokenjsonformat | jq -r . | grep AWS_ACCESS_KEY | cut -d '"' -f 4)
18+
AWS_SECRET_KEY=$(echo $tokenjsonformat | jq -r . | grep AWS_SECRET_KEY | cut -d '"' -f 4)
19+
AWS_ENVIRONMENT=$(echo $tokenjsonformat | jq -r . | grep AWS_ENVIRONMENT | cut -d '"' -f 4)
20+
AWS_SESSION_TOKEN=$(echo $tokenjsonformat | jq -r . | grep AWS_SESSION_TOKEN | cut -d '"' -f 4)
21+
aws configure set default.region $AWS_REGION
22+
aws configure set default.output json
23+
aws configure set aws_access_key_id $AWS_ACCESS_KEY
24+
aws configure set aws_secret_access_key $AWS_SECRET_KEY
25+
aws configure set aws_session_token $AWS_SESSION_TOKEN

0 commit comments

Comments
 (0)
Please sign in to comment.