1
1
#! /bin/bash
2
2
AWSENV=$1
3
+ export AWS_REGION=$2
3
4
BASE64_DECODER=" base64 -d" # option -d for Linux base64 tool
4
5
echo AAAA | base64 -d > /dev/null 2>&1 || BASE64_DECODER=" base64 -D" # option -D on MacOS
5
6
decode_base64_url () {
@@ -11,15 +12,20 @@ decode_base64_url() {
11
12
echo " $result " | tr ' _-' ' /+' | $BASE64_DECODER
12
13
}
13
14
15
+ if [ -z " $AWS_REGION " ];
16
+ then
17
+ export AWS_REGION=" us-east-1"
18
+ fi
14
19
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
20
token=$( eval $auth0cmd | jq -r .access_token )
16
21
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)
22
+ export AWS_ACCESS_KEY_ID=$( echo $tokenjsonformat | jq -r . | grep AWS_ACCESS_KEY | cut -d ' "' -f 4)
23
+ export AWS_SECRET_ACCESS_KEY=$( echo $tokenjsonformat | jq -r . | grep AWS_SECRET_KEY | cut -d ' "' -f 4)
24
+ export AWS_ENVIRONMENT=$( echo $tokenjsonformat | jq -r . | grep AWS_ENVIRONMENT | cut -d ' "' -f 4)
25
+ export AWS_SESSION_TOKEN=$( echo $tokenjsonformat | jq -r . | grep AWS_SESSION_TOKEN | cut -d ' "' -f 4)
26
+ export AWS_ACCOUNT_ID=$( echo $tokenjsonformat | jq -r . | grep AWS_ACCOUNT_ID | cut -d ' "' -f 4)
21
27
aws configure set default.region $AWS_REGION
22
28
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
29
+ aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
30
+ aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
25
31
aws configure set aws_session_token $AWS_SESSION_TOKEN
0 commit comments