@@ -108,40 +108,6 @@ scan_img() {
108108 fi
109109}
110110
111- # Function to merge multiple SARIF files into a single consolidated report
112- # This combines multiple scan results while preserving the SARIF format structure
113- #
114- # Arguments:
115- # $1 - Glob pattern of SARIF files to merge
116- # $2 - Destination file path for the merged report
117- merge_sarif_files () {
118- local glob_pattern=" $1 "
119- local dest_file=" $2 "
120-
121- info " Merging SARIF files: $glob_pattern -> $dest_file "
122-
123- # Check if any files match the pattern
124- # shellcheck disable=SC2206
125- local files=($glob_pattern )
126- if [[ ! -f " ${files[0]} " ]]; then
127- warn " No files found matching pattern: $glob_pattern "
128- return 0
129- fi
130-
131- # Merge SARIF files using jq to combine runs from multiple files
132- # shellcheck disable=SC2086
133- if ! jq -s ' {
134- "$schema": "https://json.schemastore.org/sarif-2.1.0",
135- "version": "2.1.0",
136- "runs": map(.runs) | add
137- }' $glob_pattern > " $dest_file " ; then
138- error " Failed to merge SARIF files for pattern: $glob_pattern "
139- return 1
140- fi
141-
142- success " Successfully merged ${# files[@]} files into $dest_file "
143- }
144-
145111main () {
146112 info " Starting container vulnerability scanning process..."
147113
@@ -175,13 +141,6 @@ main() {
175141 warn " Some scans failed. Check the logs above for details."
176142 fi
177143
178- # Merge SARIF files by distribution type
179- info " Merging SARIF reports by distribution..."
180- merge_sarif_files " $scans_dir /alpine*.sarif" " $tmp_dir /alpine.sarif"
181- merge_sarif_files " $scans_dir /debian*.sarif" " $tmp_dir /debian.sarif"
182- merge_sarif_files " $scans_dir /distroless*.sarif" " $tmp_dir /distroless.sarif"
183- merge_sarif_files " $scans_dir /ubuntu*.sarif" " $tmp_dir /ubuntu.sarif"
184-
185144 # Cleanup intermediate OCI directories (keep SARIF files)
186145 info " Cleaning up intermediate files..."
187146 find " $tmp_dir " -mindepth 1 -maxdepth 1 -type d -not -path " $scans_dir " -exec rm -rf {} \; 2> /dev/null || true
0 commit comments