-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstagingTokenCreator.sh
executable file
·149 lines (130 loc) · 4.11 KB
/
stagingTokenCreator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# vim:fileencoding=utf-8:ft=bash:foldmethod=marker
#-----README-----#
#You will have need to ensure the following environment variable is set in your shell:
# export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
#VARIABLES
#NOTIFIERS / BLUE SELECTOR IS FOR STAGING
NS=notify-send
DMENU='dmenu -m 0 -fn VictorMono:size=17 -nf cyan -nb black -nf cyan -sb blue'
DUN='dunstify -h int:value:'
#TESTING FOR EXISTING SECRETFILE
if [ -z ~/secretFile]; then
rm ~/secretFile
dunstify -u low "removed secretFile...CLEAN UP UP AFTER YOURSELF!"
fi
#DIRECTORIES AND FILES
BASE=~/capacity/repos/dev/
SERVICE=$(find ${BASE} -type f | rg "secrets.yaml" | xargs dirname | awk -F / '{print $9}' | uniq | ${DMENU} -p "Select staging token:")
if [ "$?" -eq 0 ]; then
continue
else
dunstify -u critical "Nothing Selected"
exit 1
fi
#BRANCH TO MODIFY
DIR=$(find ${BASE} -type d|rg helm|rg ${SERVICE}|sed -n 1p|awk -F / '{print $1"/"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"$8"/"$9}')
cd ${DIR}
#ENTER TICKET NUMBER"
TIX=$(echo " " | ${DMENU} -p "Enter FULL ticket Number")
if [ "$?" -eq 0 ]; then
continue
else
dunstify -u critical "No ticket number"
exit 2
fi
##GIT CHECKOUT TICKET NAME
git pull
git checkout master ${DIR}
git checkout -b ${TIX}
#TESTING GIT CHECKOUT
if [ "$?" -eq 0 ]; then
${NS} "Successful Checkout"
else
${NS} -u critical "I didn't reach the targeted destination!! "$?""
exit 3
fi
#SELECT FILE
FILE=${DIR}/helm/${SERVICE}/secrets.staging.yaml
##MAKING TOKEN AND ALLOWING FOR K8S TO EXEC INTO POD AND MAKE TOKEN
function MAKETOKEN() {
if [ -z ~/secretFile ]; then
stagingToken $1 | sed -n 2p > ~/secretFile
$DFYL "Made secretFile"
else
rm ~/secretFile
$DFYL "Clean up after yourself! Removed ~/secretFile"
stagingToken $1 | sed -n 2p > ~/secretFile
fi
}
#CALL TOKEN AND MAKETOKEN
DFYL='dunstify -u low'
DFYN='dunstify -u normal'
${DFYL} "Making..."
MAKETOKEN ${SERVICE}
#USER NOTIFICATIONS
if [ "$?" -eq 0 ]; then
${DFYL} ${TOKEN}
${NS} -u low "Token Created"
else
${DFYL} "Exit"
${NS} -u low "Failed to write secretFile,\"$?\""
exit 4
fi
#EDIT SECRETS FILE //THERE ARE TESTS BETWEEN EACH STEP
#DECRYPTING FILE
helm secrets dec ${FILE}
##TESTING
if [ "$?" -eq 0 ]; then
${DFYL} "File Decrypted"
sleep 2
else
${NS} -u critical "I didn't decrypt the file "$?""
exit 5
fi
sleep 2
#REMOVE OLD TOKEN AND REPLACE WITH NEW TOKEN
sed -i "s/CORE_API_TOKEN:.*/CORE_API_TOKEN:\ \\$(cat ~/secretFile)/" ${FILE}.dec
##TESTING
if [ "$?" -eq 0 ]; then
${DFYN} "Updated token in ${FILE}.dec"
else
${NS} -u critical "I didn't correctly upgrade the ${FILE}.dec "$?""
exit 6
fi
#REMOVe old secrets.Staging.yaml file and rename $FILE
rm ${FILE} && mv ${FILE}.dec ${FILE}
#RE-ENCRYPT FILE
helm secrets enc ${FILE}.dec
##TESTING
if [ "$?" -eq 0 ]; then
${DFYL} "Successfully Re-encrypted ${FILE}.dec"
else
${NS} -u critical "I did not RE-ENCRYPT ${FILE}.dec "$?""
exit 7
fi
sleep 2
#GIT BOILERPLATE TO COMMIT AND PUSH
#COMMIT THE FILES
git add ${FILE}
git commit -m "Updated ${TIX} Staging API tokens"
#TESTING
if [ "$?" -eq 0 ]; then
${DUN}75 "Commited branch ${TIX}"
else
${NS} -u critical "I did NOT successfully commit branch ${TIX} "$?""
exit 8
fi
#PUSH THE FILES && OPEN URL IN GOOGLE-CHROME
git push --set-upstream origin ${TIX} | rg https | xargs google-chrome
#TESTING GIT PUSH
if [ "$?" -eq 0 ]; then
${DFYL} "Pushed to gitlab!"
rm ~/secretFile
${DFYN} "secretFile removed"
exit 0
else
${NS} "Did not push the secrets file to gitlab for ${SERVICE}."
${DFYN} "secretFile removed"
exit 9
fi