diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6d98284 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM alpine:3.11.6 + +WORKDIR /app + +COPY [ "switchRole.sh", "getParamStore.sh", "./var/" ] + +ENV PYTHON_VERSION 3.8.2-r0 + +ENV PATH /usr/local/bin:$PATH + +RUN apk add --update --no-cache \ + autoconf \ + automake \ + bash \ + curl \ + g++ \ + gcc \ + jq \ + libtool \ + make \ + python3-dev \ + python3=$PYTHON_VERSION \ + zip \ + && rm -rf /var/cache/apk/* + +RUN cd /usr/local/bin \ + && rm -f /usr/bin/python \ + && ln -s /usr/bin/python3 python + +RUN pip3 install --upgrade --no-cache-dir \ + pip \ + autopep8 \ + awscli \ + boto3 \ + coverage \ + jq \ + pandas \ + pylint \ + requests \ + s3pypi \ + setuptools \ + sphinx \ + sphinx-rtd-theme diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..65b30e5 --- /dev/null +++ b/README.rst @@ -0,0 +1,11 @@ +============= +rdp-python3 +============= + +**Description:** + +Docker for python 3 + +**Note:** + +Please use pip3 instead of pip when instead installing python packages diff --git a/getParamStore.sh b/getParamStore.sh new file mode 100644 index 0000000..1d789c9 --- /dev/null +++ b/getParamStore.sh @@ -0,0 +1,46 @@ +#!/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 \ No newline at end of file diff --git a/switchRole.sh b/switchRole.sh new file mode 100644 index 0000000..c5d6096 --- /dev/null +++ b/switchRole.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ $# -ne 2 ]; then + echo "Error! Too many arguments provided\nsource /var/switchRole.sh " + 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" \ No newline at end of file