Skip to content

Commit

Permalink
Refactored assume role script
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjwwalker committed Jun 12, 2022
1 parent 5d2c88a commit afe1d99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ pipeline {
steps {
script {
sh '''
source ./build/aws/assume-role.sh;
assumeRole;
./build/aws/assume-role.sh;
aws ecr get-login-password | docker login -u AWS --password-stdin "https://$(aws sts get-caller-identity --query 'Account' --output text).dkr.ecr.$(aws configure get region).amazonaws.com"
docker tag cjww-development/gatekeeper:${env.TAG_NAME} 929252955305.dkr.ecr.eu-west-2.amazonaws.com/gatekeeper:${env.TAG_NAME}
docker push 047459333450.dkr.ecr.eu-west-2.amazonaws.com/gatekeeper:${env.TAG_NAME}
Expand Down
26 changes: 12 additions & 14 deletions build/aws/assume-role.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

#
# Copyright 2022 CJWW Development
Expand All @@ -16,18 +16,16 @@
# limitations under the License.
#

assumeRole() {
set +x
SESSIONID=$(date +"%s")
set +x
SESSIONID=$(date +"%s")

RESULT=($(aws sts assume-role --role-arn "$ROLE_ARN" \
--role-session-name "$SESSIONID" \
--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' \
--output text))
RESULT=($(aws sts assume-role --role-arn "$ROLE_ARN" \
--role-session-name "$SESSIONID" \
--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' \
--output text))

export AWS_ACCESS_KEY_ID=${RESULT[0]}
export AWS_SECRET_ACCESS_KEY=${RESULT[1]}
export AWS_SECURITY_TOKEN=${RESULT[2]}
export AWS_SESSION_TOKEN=${AWS_SECURITY_TOKEN}
set -x
}
export AWS_ACCESS_KEY_ID=${RESULT[0]}
export AWS_SECRET_ACCESS_KEY=${RESULT[1]}
export AWS_SECURITY_TOKEN=${RESULT[2]}
export AWS_SESSION_TOKEN=${AWS_SECURITY_TOKEN}
set -x

0 comments on commit afe1d99

Please sign in to comment.