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