Skip to content

Commit 06741e2

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

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

awsconfiguration.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
AWSENV=$1
3-
export AWS_REGION=$2
3+
AWS_REGION=$2
44
BASE64_DECODER="base64 -d" # option -d for Linux base64 tool
55
echo AAAA | base64 -d > /dev/null 2>&1 || BASE64_DECODER="base64 -D" # option -D on MacOS
66
decode_base64_url() {
@@ -14,18 +14,28 @@ decode_base64_url() {
1414

1515
if [ -z "$AWS_REGION" ];
1616
then
17-
export AWS_REGION="us-east-1"
17+
AWS_REGION="us-east-1"
1818
fi
1919
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\"}'")
2020
token=$( eval $auth0cmd | jq -r .access_token )
2121
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)
2727
aws configure set default.region $AWS_REGION
2828
aws configure set default.output json
2929
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
3030
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

Comments
 (0)