-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheck_secrets_1.sh
executable file
·77 lines (62 loc) · 2.59 KB
/
eck_secrets_1.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
#!/usr/bin/env bash
# count of array
count=`jq '.Items | length' "${1}"`
if [ ${count} = 0 ]; then
exit
fi
echo "========================================================================================="
echo "SECRETS Summary"
echo "========================================================================================="
echo ""
jq -r '
[.Items
| sort_by(.metdata.name)[]
| {
"NAME": (.metadata.name // "-"),
"TYPE": (.type // "-"),
"APIVERSION": (select(.metadata.ownerReferences != null) |.metadata.ownerReferences[] | select(.name !=null) | ((.apiVersion) // "-")),
"OWNER": (select(.metadata.ownerReferences != null) |.metadata.ownerReferences[] | select(.name !=null) | ((.kind + "/" + .name) // "-")),
"CREATION TIME": (.metadata.creationTimestamp // "-")
}
]
| (.[0] |keys_unsorted | @tsv),(.[]|.|map(.) |@tsv)' "${1}" 2>/dev/null | column -ts $'\t'
echo ""
for ((i=0; i<$count; i++))
do
secret=`jq -r '.Items['${i}'].metadata.name' "${1}"`
echo "========================================================================================="
echo "Secret: ${secret} DESCRIBE"
echo "========================================================================================="
echo ""
echo ""
# name
printf "%-20s %s\\n" "Name:" "${secret}"
# namespace
value=$(jq -r '.Items['${i}'] | (.metadata.namespace // "-")' "${1}" 2>/dev/null)
printf "%-20s %s\\n" "Namespace:" "${value}"
# apiversion
value=$(jq -r '.Items['${i}'] | select(.metadata.ownerReferences != null) |.metadata.ownerReferences[] | select(.controller==true) | ((.apiVersion) // "-")' "${1}")
printf "%-20s %s\\n" "apiVersion:" "${value}"
# owner
value=$(jq -r '.Items['${i}'] | select(.metadata.ownerReferences != null) |.metadata.ownerReferences[] | select(.controller==true) | ((.kind + "/" + .name) // "-")' "${1}")
printf "%-20s %s\\n" "Owner:" "${value}"
# labels
printf "%-20s \n" "Lables:"
jq -r '.Items['${i}'].metadata.labels | (to_entries[] | "\(.key)=\(.value)") | select(length >0)' "${1}" 2>/dev/null | sed "s/^/ /"
# annotations
printf "%-20s \n" "Annotations:"
jq -r '.Items['${i}'].metadata.annotations | (to_entries[] | "\(.key)=\(.value)") | select(length >0)' "${1}" 2>/dev/null | sed "s/^/ /"
# events
if [ -f eck_events.txt ]; then
echo ""
printf "%-20s \n" "Events:"
cat eck_events.txt | grep "Secret"
echo ""
elif [ -f "${WORKDIR}/${namespace}/eck_events.txt" ]; then
echo ""
printf "%-20s \n" "Events:"
cat "${WORKDIR}/${namespace}/eck_events.txt" | grep "Secret"
echo ""
fi
done # end of i (main loop)
echo ""