@@ -19,9 +19,9 @@ function echoSection {
19
19
20
20
unset_empty_vars () {
21
21
echoSection " Unsetting empty vars"
22
- for var in $( env) ; do
23
- if [[ " ${var##* =} " == " \$ {{${var% =* } }}" ]]; then
24
- echo " Unsetting ${var% =* } " ;
22
+ for var in $( env) ; do
23
+ if [[ " ${var##* =} " == " \$ {{${var% =* } }}" ]]; then
24
+ echo " Unsetting ${var% =* } " ;
25
25
unset ${var% =* } ;
26
26
fi ;
27
27
done
@@ -34,8 +34,8 @@ set_trivy_ignore() {
34
34
if [[ ! -z $TRIVY_IGNORE_FILE ]]; then
35
35
stat -c " %n" " $TRIVY_IGNORE_FILE "
36
36
cp $TRIVY_IGNORE_FILE $TRIVY_IGNOREFILE
37
- fi
38
- local IFS=$' ,'
37
+ fi
38
+ local IFS=$' ,'
39
39
for cve in $TRIVY_IGNORE_LIST ; do
40
40
echo $cve >> $TRIVY_IGNOREFILE
41
41
done
@@ -62,24 +62,31 @@ generate_images_list() {
62
62
63
63
scan_template () {
64
64
local image=$1
65
- local object=$( trivy -q -f json --cache-dir ${CACHE_DIR} --ignorefile ${TRIVY_IGNOREFILE} ${image} | sed ' s|null|\[\]|' )
66
- count=$( echo $object | jq length)
65
+ local object=$( trivy image -q -f json --cache-dir ${CACHE_DIR} --ignorefile ${TRIVY_IGNOREFILE} ${image} | sed ' s|null|\[\]|' )
66
+ count=$( echo $object | jq ' .Results | length' )
67
67
for (( i = 0 ; i < $count ; i++ )) ; do
68
- local vuln_length=$( echo $object | jq -r --arg index " ${i} " ' .[($index|tonumber)].Vulnerabilities | length' )
68
+ local vuln_length=$( echo $object | jq -r --arg index " ${i} " ' .Results [($index|tonumber)].Vulnerabilities // [] | length' )
69
69
if [[ " $vuln_length " -eq " 0" ]] && [[ " $SKIP_EMPTY " == " true" ]]; then
70
70
continue
71
71
fi
72
- echo -E " \n" Target: $( echo $object | jq -r --arg index " ${i} " ' .[($index|tonumber)].Target' )
72
+ echo -E " \n" Target: $( echo $object | jq -r --arg index " ${i} " ' .Results [($index|tonumber)].Target' )
73
73
echo " ..."
74
- echo $object | jq -r --arg index " ${i} " ' .[($index|tonumber)].Vulnerabilities[] | "\(.PkgName) \(.VulnerabilityID) \(.Severity)"' | column -t | sort -k3
74
+ if [[ " $vuln_length " -eq " 0" ]]; then
75
+ # Return a non-empty default value
76
+ echo " No vulnerabilities found."
77
+ continue
78
+ fi
79
+ echo $object | jq -r --arg index " ${i} " ' .Results[($index|tonumber)].Vulnerabilities // [] | .[] | "\(.PkgName) \(.VulnerabilityID) \(.Severity)"' | column -t | sort -k3
75
80
done
76
81
}
77
82
78
83
slack_image_section () {
79
84
local image=$1
80
85
local header=" *${image} *"
81
86
local body=$( scan_template $image | awk ' {print}' ORS=' \\n' )
82
- if [[ -z $body ]]; then return ; fi
87
+ if [[ -z $body ]]; then
88
+ return
89
+ fi
83
90
echo -E " {
84
91
\" type\" : \" section\" ,
85
92
\" text\" : {
@@ -102,7 +109,7 @@ main() {
102
109
fi
103
110
104
111
echoSection " Update trivy DB"
105
- trivy --download-db-only --cache-dir ${CACHE_DIR}
112
+ trivy image --download-db-only --cache-dir ${CACHE_DIR}
106
113
107
114
SLACK_REPORT_MESSAGE=' {"blocks":[]}'
108
115
0 commit comments