Skip to content

Commit 6fa41cd

Browse files
authored
Merge pull request #31 from topcoder-platform/dev-ps-var
Dev ps var
2 parents ebcd984 + 14a5d69 commit 6fa41cd

File tree

3 files changed

+256
-1
lines changed

3 files changed

+256
-1
lines changed

master_deploy.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SHARED_PROPERTY_FILENAME=""
1818
TAG=""
1919
SEC_LIST=""
2020
SECPS_LIST=""
21+
ARG_SECPS_LIST=""
2122
#COUNTER_LIMIT=12
2223

2324
if [ -z "$COUNTER_LIMIT" ]; then
@@ -399,6 +400,29 @@ ECS_template_create_register() {
399400
IFS=$o
400401
done
401402
fi
403+
if [ -z $ARG_SECPS_LIST ];
404+
then
405+
log "No ps file provided"
406+
else
407+
Buffer_seclist=$(echo $ARG_SECPS_LIST | sed 's/,/ /g')
408+
for listname in $Buffer_seclist;
409+
do
410+
local o=$IFS
411+
IFS=$(echo -en "\n\b")
412+
k=$listname
413+
echo $k
414+
aws ssm get-parameters-by-path --path $k --query "Parameters[*].{Name:Name}" > paramnames.json
415+
###paramnames=$(cat paramnames.json | jq -r .[].Name | rev | cut -d / -f 1 | rev)
416+
for s in $(cat paramnames.json | jq -r .[].Name )
417+
do
418+
varname=$(echo $s | rev | cut -d / -f 1 | rev)
419+
varvalue="arn:aws:ssm:$AWS_REGION:$AWS_ACCOUNT_ID:parameter$s"
420+
psenvaddition "$varname" "$varvalue"
421+
#echo "$varname" "$varvalue"
422+
done
423+
IFS=$o
424+
done
425+
fi
402426
log "Environment has updated"
403427

404428
# Log Configuration
@@ -857,7 +881,7 @@ deploy_lambda_package()
857881
# Input Collection and validation
858882
input_parsing_validation()
859883
{
860-
while getopts .d:h:i:e:l:t:v:s:p:g:c:m:. OPTION
884+
while getopts .d:h:i:e:l:j:t:v:s:p:g:c:m:. OPTION
861885
do
862886
case $OPTION in
863887
d)
@@ -876,6 +900,9 @@ input_parsing_validation()
876900
l)
877901
SECPS_LIST=$OPTARG
878902
;;
903+
j)
904+
ARG_SECPS_LIST=$OPTARG
905+
;;
879906
t)
880907
TAG=$OPTARG
881908
;;

psvar-processor.sh

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
usage()
4+
{
5+
cat << EOF
6+
usage: $0 options
7+
8+
This script needs to be executed with below options.
9+
10+
OPTIONS:
11+
-e environment
12+
-t type appenv,appconf and appjson
13+
-p parameter store path without final slash
14+
-l parameter store list without final slash
15+
16+
EOF
17+
}
18+
19+
create_env_file_format()
20+
{
21+
file_name=$1
22+
fetch_path=$2
23+
echo $fetch_path
24+
echo $file_name
25+
aws ssm get-parameters-by-path --with-decryption --path $fetch_path --query "Parameters[*].{Name:Name, Value:Value}" >fetched_parameters.json
26+
cat fetched_parameters.json | jq -r '.[] | "export " + .Name + "=\"" + .Value + "\"" ' | sed -e "s~$fetch_path/~~" >${file_name}_env
27+
rm -rf fetched_parameters.json
28+
}
29+
30+
create_conf_file_format()
31+
{
32+
file_name=$1
33+
fetch_path=$2
34+
aws ssm get-parameters-by-path --with-decryption --path $fetch_path --query "Parameters[*].{Name:Name, Value:Value}" >fetched_parameters.json
35+
cat fetched_parameters.json | jq -r '.[] | .Name + "=\"" + .Value + "\"" ' | sed -e "s~$fetch_path/~~" >${file_name}.conf
36+
rm -rf fetched_parameters.json
37+
}
38+
39+
create_json_file_format()
40+
{
41+
file_name=$1
42+
fetch_path=$2
43+
echo $fetch_path
44+
echo $file_name
45+
echo "aws ssm get-parameters-by-path --with-decryption --path $fetch_path --query \"Parameters[*].{Name:Name, Value:Value}\""
46+
aws ssm get-parameters-by-path --with-decryption --path $fetch_path --query "Parameters[*].{Name:Name, Value:Value}" >fetched_parameters.json
47+
cat fetched_parameters.json | jq -r ' . |= (map({ (.Name): .Value }) | add)' | sed -e "s~$fetch_path/~~" >${file_name}.json
48+
# rm -rf fetched_parameters.json
49+
}
50+
51+
create_jsonso_file_format()
52+
{
53+
file_name=$1
54+
fetch_path=$2
55+
echo $fetch_path
56+
echo $file_name
57+
echo "aws ssm get-parameters --with-decryption --name $fetch_path | jq '.Parameters | .[] | .Value' | jq '.|fromjson'"
58+
aws ssm get-parameters --with-decryption --name $fetch_path | jq '.Parameters | .[] | .Value' | jq '.|fromjson' >${file_name}.json
59+
# rm -rf fetched_parameters.json
60+
}
61+
62+
fetching_specific_path()
63+
{
64+
type_to_fetch=$1
65+
PS_PATH=${PS_PATH%/}
66+
fname=${PS_PATH##*/}
67+
fpath=$PS_PATH
68+
echo $fpath
69+
echo $PS_PATH
70+
if [ "$type_to_fetch" == "appenv" ]
71+
then
72+
create_env_file_format $fname $fpath
73+
fi
74+
if [ "$type_to_fetch" == "appconf" ]
75+
then
76+
create_conf_file_format $fname $fpath
77+
fi
78+
if [ "$type_to_fetch" == "appjson" ]
79+
then
80+
create_json_file_format $fname $fpath
81+
fi
82+
if [ "$type_to_fetch" == "appjsonso" ]
83+
then
84+
create_jsonso_file_format $fname $fpath
85+
fi
86+
}
87+
88+
fetching_multiple_path()
89+
{
90+
type_to_fetch=$1
91+
Buffer_seclist=$(echo $PS_PATH_LIST | sed 's/,/ /g' )
92+
for listname in $Buffer_seclist;
93+
do
94+
listname=${listname%/}
95+
fname=${listname##*/}
96+
fpath=$listname
97+
if [ "$type_to_fetch" == "appenv" ]
98+
then
99+
create_env_file_format $fname $fpath
100+
fi
101+
if [ "$type_to_fetch" == "appconf" ]
102+
then
103+
create_conf_file_format $fname $fpath
104+
fi
105+
if [ "$type_to_fetch" == "appjson" ]
106+
then
107+
create_json_file_format $fname $fpath
108+
fi
109+
if [ "$type_to_fetch" == "appjsonso" ]
110+
then
111+
create_jsonso_file_format $fname $fpath
112+
fi
113+
done
114+
}
115+
116+
117+
while getopts .t:e:p:l:. OPTION
118+
do
119+
case $OPTION in
120+
e)
121+
ENV=$OPTARG
122+
;;
123+
t)
124+
APP_TYPE=$OPTARG
125+
;;
126+
p)
127+
PS_PATH=$OPTARG
128+
;;
129+
l)
130+
PS_PATH_LIST=$OPTARG
131+
;;
132+
?)
133+
log "additional param required"
134+
usage
135+
exit
136+
;;
137+
esac
138+
done
139+
140+
ENV_CONFIG=`echo "$ENV" | tr '[:upper:]' '[:lower:]'`
141+
APP_TYPE_LOWERCASE=`echo "$APP_TYPE" | tr '[:upper:]' '[:lower:]'`
142+
143+
echo "APP_TYPE: $APP_TYPE_LOWERCASE"
144+
echo "PS_PATH: $PS_PATH"
145+
echo "PS_PATH_LIST: $PS_PATH_LIST"
146+
147+
if [ "$APP_TYPE_LOWERCASE" == "appenv" ]
148+
then
149+
echo "env configuration"
150+
if [ -z $PS_PATH ];
151+
then
152+
echo "Info: no ps path"
153+
else
154+
fetching_specific_path $APP_TYPE_LOWERCASE
155+
fi
156+
if [ -z $PS_PATH_LIST ];
157+
then
158+
echo "Info: no path list provided. So skipping pathlist"
159+
else
160+
fetching_multiple_path $APP_TYPE_LOWERCASE
161+
fi
162+
fi
163+
164+
if [ "$APP_TYPE_LOWERCASE" == "appconf" ]
165+
then
166+
echo "conf file configuration"
167+
if [ -z $PS_PATH ];
168+
then
169+
echo "Info: no ps path"
170+
else
171+
fetching_specific_path $APP_TYPE_LOWERCASE
172+
fi
173+
if [ -z $PS_PATH_LIST ];
174+
then
175+
echo "Info: no path list provided. So skipping pathlist"
176+
else
177+
fetching_multiple_path $APP_TYPE_LOWERCASE
178+
fi
179+
fi
180+
181+
if [ "$APP_TYPE_LOWERCASE" == "appjson" ]
182+
then
183+
echo "json file configuration"
184+
if [ -z $PS_PATH ];
185+
then
186+
echo "Info: no ps path"
187+
else
188+
fetching_specific_path $APP_TYPE_LOWERCASE
189+
fi
190+
if [ -z $PS_PATH_LIST ];
191+
then
192+
echo "Info: no path list provided. So skipping pathlist"
193+
else
194+
fetching_multiple_path $APP_TYPE_LOWERCASE
195+
fi
196+
fi
197+
198+
if [ "$APP_TYPE_LOWERCASE" == "appjsonso" ]
199+
then
200+
echo "json file configuration"
201+
if [ -z $PS_PATH ];
202+
then
203+
echo "Info: no ps path"
204+
else
205+
fetching_specific_path $APP_TYPE_LOWERCASE
206+
fi
207+
if [ -z $PS_PATH_LIST ];
208+
then
209+
echo "Info: no path list provided. So skipping pathlist"
210+
else
211+
fetching_multiple_path $APP_TYPE_LOWERCASE
212+
fi
213+
fi

uploadjson-ps.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
UPLOAD_FILENAME=$1
4+
PARAMETER_PATH=$2
5+
6+
cat $UPLOAD_FILENAME | jq -r ' . ' | jq --arg PARAMETER_PATH $PARAMETER_PATH ' . | to_entries[] | { "Name": ($PARAMETER_PATH+"/"+.key) , "Value": .value, "Type" : "SecureString" } ' | jq -s . >upload_object.json
7+
o=$IFS
8+
IFS=$(echo -en "\n\b")
9+
10+
for s in $(cat upload_object.json | jq -c .[] )
11+
do
12+
echo $s>cli-input.json
13+
aws ssm put-parameter --cli-input-json file://cli-input.json
14+
done
15+
IFS=$o

0 commit comments

Comments
 (0)