forked from kelvinlow117/rdp-python3
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jerrypan90/master
added new cicd workflow
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |