Skip to content

Commit ae1e1f2

Browse files
committed
code updated to pass psvar as argument
1 parent ebcd984 commit ae1e1f2

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed

master_deploy.sh

Lines changed: 27 additions & 0 deletions
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
@@ -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: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
fetching_specific_path()
52+
{
53+
type_to_fetch=$1
54+
PS_PATH=${PS_PATH%/}
55+
fname=${PS_PATH##*/}
56+
fpath=$PS_PATH
57+
echo $fpath
58+
echo $PS_PATH
59+
if [ "$type_to_fetch" == "appenv" ]
60+
then
61+
create_env_file_format $fname $fpath
62+
fi
63+
if [ "$type_to_fetch" == "appconf" ]
64+
then
65+
create_conf_file_format $fname $fpath
66+
fi
67+
if [ "$type_to_fetch" == "appjson" ]
68+
then
69+
create_json_file_format $fname $fpath
70+
fi
71+
}
72+
73+
fetching_multiple_path()
74+
{
75+
type_to_fetch=$1
76+
Buffer_seclist=$(echo $PS_PATH_LIST | sed 's/,/ /g' )
77+
for listname in $Buffer_seclist;
78+
do
79+
listname=${listname%/}
80+
fname=${listname##*/}
81+
fpath=$listname
82+
if [ "$type_to_fetch" == "appenv" ]
83+
then
84+
create_env_file_format $fname $fpath
85+
fi
86+
if [ "$type_to_fetch" == "appconf" ]
87+
then
88+
create_conf_file_format $fname $fpath
89+
fi
90+
if [ "$type_to_fetch" == "appjson" ]
91+
then
92+
create_json_file_format $fname $fpath
93+
fi
94+
done
95+
}
96+
97+
98+
while getopts .t:e:p:l:. OPTION
99+
do
100+
case $OPTION in
101+
e)
102+
ENV=$OPTARG
103+
;;
104+
t)
105+
APP_TYPE=$OPTARG
106+
;;
107+
p)
108+
PS_PATH=$OPTARG
109+
;;
110+
l)
111+
PS_PATH_LIST=$OPTARG
112+
;;
113+
?)
114+
log "additional param required"
115+
usage
116+
exit
117+
;;
118+
esac
119+
done
120+
121+
ENV_CONFIG=`echo "$ENV" | tr '[:upper:]' '[:lower:]'`
122+
APP_TYPE_LOWERCASE=`echo "$APP_TYPE" | tr '[:upper:]' '[:lower:]'`
123+
124+
echo "APP_TYPE: $APP_TYPE_LOWERCASE"
125+
echo "PS_PATH: $PS_PATH"
126+
echo "PS_PATH_LIST: $PS_PATH_LIST"
127+
128+
if [ "$APP_TYPE_LOWERCASE" == "appenv" ]
129+
then
130+
echo "env configuration"
131+
if [ -z $PS_PATH ];
132+
then
133+
echo "Info: no ps path"
134+
else
135+
fetching_specific_path $APP_TYPE_LOWERCASE
136+
fi
137+
if [ -z $PS_PATH_LIST ];
138+
then
139+
echo "Info: no path list"
140+
else
141+
fetching_multiple_path $APP_TYPE_LOWERCASE
142+
fi
143+
fi
144+
145+
if [ "$APP_TYPE_LOWERCASE" == "appconf" ]
146+
then
147+
echo "conf file configuration"
148+
if [ -z $PS_PATH ];
149+
then
150+
echo "Info: no ps path"
151+
else
152+
fetching_specific_path $APP_TYPE_LOWERCASE
153+
fi
154+
if [ -z $PS_PATH_LIST ];
155+
then
156+
echo "Info: no path list"
157+
else
158+
fetching_multiple_path $APP_TYPE_LOWERCASE
159+
fi
160+
fi
161+
162+
if [ "$APP_TYPE_LOWERCASE" == "appjson" ]
163+
then
164+
echo "json file configuration"
165+
if [ -z $PS_PATH ];
166+
then
167+
echo "Info: no ps path"
168+
else
169+
fetching_specific_path $APP_TYPE_LOWERCASE
170+
fi
171+
if [ -z $PS_PATH_LIST ];
172+
then
173+
echo "Info: no path list"
174+
else
175+
fetching_multiple_path $APP_TYPE_LOWERCASE
176+
fi
177+
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)