Skip to content

Commit e214d93

Browse files
Gunasekar KGunasekar K
Gunasekar K
authored and
Gunasekar K
committed
aws configuration dynamic
1 parent c7f0642 commit e214d93

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

awsconfiguration.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
AWSENV=$1
3+
export AWS_REGION=$2
34
BASE64_DECODER="base64 -d" # option -d for Linux base64 tool
45
echo AAAA | base64 -d > /dev/null 2>&1 || BASE64_DECODER="base64 -D" # option -D on MacOS
56
decode_base64_url() {
@@ -11,15 +12,20 @@ decode_base64_url() {
1112
echo "$result" | tr '_-' '/+' | $BASE64_DECODER
1213
}
1314

15+
if [ -z "$AWS_REGION" ];
16+
then
17+
export AWS_REGION="us-east-1"
18+
fi
1419
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\"}'")
1520
token=$( eval $auth0cmd | jq -r .access_token )
1621
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)
2127
aws configure set default.region $AWS_REGION
2228
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
2531
aws configure set aws_session_token $AWS_SESSION_TOKEN

0 commit comments

Comments
 (0)