Skip to content

Commit

Permalink
Merge pull request #1 from jerrypan90/master
Browse files Browse the repository at this point in the history
added new cicd workflow
  • Loading branch information
leroyleejh authored May 21, 2020
2 parents e8a986b + 7df305e commit 8841ecd
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM alpine:3.8

COPY ["switchRole.sh", "getParamStore.sh", "./var/"]

WORKDIR /rdp-python3

ENV PYTHON_VERSION 3.6.6-r0
Expand Down
47 changes: 47 additions & 0 deletions getParamStore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

#This script will generate a file env.sh
#To use: bash getEnv.sh [path...]
#Please execute
# $ source env.sh
#to apply environment variables

if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi
ARGUMENTS="$@"
OUT_FILE="/var/env.sh"
echo '#!/bin/sh' > $OUT_FILE

# non greedy capture group 1, | greedy capture till end of string

# use for mac os
# SED_COMMAND="sed \"s^\([^\|]*\)\|\(.*\)^export \\1='\\2'^\""

# use for aws linux
SED_COMMAND="sed \"s^\([^|]*\)|\(.*\)^export \\1='\\2'^\""

function exportToFile() {
old_IFS=$IFS
#set delimiter to only newline
IFS=$'\n'
for param in `jq -n "$1" | jq -r '.[].Value'`
do
# echo $param
param=$(sed "s^'^'\\\''^" <<< $param) #escape all single quotes
# echo $param
param=`eval $SED_COMMAND <<< $param`
# echo "$param"
echo $param >> $OUT_FILE
# echo "echo $val" >> $OUT_FILE
done
#restore delimiter
IFS=$old_IFS
}
for var in $ARGUMENTS
do
PARAMSTORE=`aws ssm get-parameters-by-path --path "$var" --no-paginate --recursive | jq -r '.Parameters'`
exportToFile "$PARAMSTORE"
done
22 changes: 22 additions & 0 deletions switchRole.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

if [ $# -ne 2 ]; then
echo "Error! Too many arguments provided\nsource /var/switchRole.sh <AWS_ROLE> <AWS_REGION>"
exit 1
fi

echo "Start of Switch Role"

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_DEFAULT_REGION

# switch role
aws sts assume-role --role-arn $1 --role-session-name rdp-develop-access > assume-role-output.txt
export AWS_ACCESS_KEY_ID=`cat assume-role-output.txt | jq -r '.Credentials.AccessKeyId'`
export AWS_SECRET_ACCESS_KEY=`cat assume-role-output.txt | jq -r '.Credentials.SecretAccessKey'`
export AWS_SESSION_TOKEN=`cat assume-role-output.txt | jq -r '.Credentials.SessionToken'`
export AWS_DEFAULT_REGION=$2

echo "End of Switch Role"

0 comments on commit 8841ecd

Please sign in to comment.