-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenCreatorBak.sh
executable file
·116 lines (96 loc) · 2.63 KB
/
tokenCreatorBak.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
#!/bin/bash
#-----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:'
#DIRECTORIES AND FILES
BASE=/home/n0ko/capacity/repos/dev
SERVICE=$(fd --full-path -td -d2 ${BASE} | awk -F / '{print $3}' | sort | ${DMENU} -p "Select staging token:")
#BRANCH TO MODIFY
DIR=$(fd --full-path -td -d3 ${BASE} | rg ${SERVICE})
cd ${DIR}
#ENTER TICKET NUMBER"
TIX=$(echo " " | ${DMENU} -p "Enter FULL ticket Number")
##GIT CHECKOUT TICKET NAME
git checkout master ${DIR}
git pull ${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 1
fi
#SELECT FILE
FILE=${BASE}${DIR}/helm/${SERVICE}/secrets.staging.yaml
##MAKING TOKEN AND ALLOWING FOR K8S TO EXEC INTO POD AND MAKE TOKEN
function MAKETOKEN() {
stagingToken $1 | rg -i -A 1 core | sed -n 2p
}
#CALL TOKEN
MAKETOKEN ${SERVICE}
sleep 3
#USER NOTIFICATIONS
${DUN}0 "Making..."
##TESTING
if [ '$?' -eq 0 ]; then
${DUN}100 "Token Created"
else
${NS} -u critical "I didn't reach the targeted destination!! '$?'"
exit 1
fi
#EDIT SECRETS FILE //THERE ARE TESTS BETWEEN EACH STEP
#DECRYPTING FILE
helm secrets dec ${FILE}
##TESTING
if [ '$?' -eq 0 ]; then
${DUN}50 "File Decrypted"
sleep 2
else
${NS} -u critical "I didn't decrypt the file '$?'"
exit 1
fi
#REMOVE OLD TOKEN AND REPLACE WITH NEW TOKEN
sed -i "s/TOKEN:.*/${MAKETOKEN}/" ${FILE}
##TESTING
if [ '$?' -eq 0 ]; then
${DUN}50 "Updated token in ${FILE}"
else
${NS} -u critical "I didn't correctly upgrade the ${FILE} '$?'"
exit 1
fi
#RE-ENCRYPT FILE
helm secrets enc ${FILE}
##TESTING
if [[ '$?' -eq 0 ]]; then
${DUN}50 "Successfully Re-encrypted ${FILE}"
else
${NS} -u critical "I didn't reach the targeted destination!! '$?'"
exit 1
fi
sleep 2
#GIT BOILERPLATE TO COMMIT AND PUSH
#COMMIT THE FILES
git commit -am "Updated ${TIX} Staging API tokens"
#TESTING
if [ '$?' -eq 0 ]; then
${DUN}75 "Commited branch ${TIX}"
else
${NS} -u critical "I didn not successfully commit to branch ${TIX} '$?'"
exit 1
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
${DUN}100 "Pushed to gitlab!"
exit 0
else
${NS} "Did not push the secrets file to gitlab for ${SERVICE}."
exit 1
fi