Skip to content

Commit

Permalink
script for Go Vulnerability Management
Browse files Browse the repository at this point in the history
  • Loading branch information
ivvist committed Oct 3, 2023
1 parent 587c231 commit 2256177
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions scripts/execgovuln.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Execute govulncheck
govulncheck ./... >> golulnres

# Main text file
main_file="golulnres"
# Exception file
exception_file=".govulnc-exclude"

# Create a temporary file to store the filtered content
temp_file="filtered.txt"

# Read the exception codes into an array
mapfile -t exception_codes < "$exception_file"

# Initialize a flag to determine whether to keep or skip a section
skip_section=0

# Loop through the main text file
while IFS= read -r line; do
# Check if the line starts with "Vulnerability #"
if [[ $line == "Vulnerability #"* ]]; then
# Extract the code from the line
code="${line##*: }"
# Check if the code is in the exception list
if [[ " ${exception_codes[*]} " =~ " $code " ]]; then
skip_section=1 # Set the flag to skip this section
else
skip_section=0 # Set the flag to keep this section
fi
fi

# If the section is not in the exception list, write it to the temp file
if [ $skip_section -eq 0 ]; then
echo "$line" >> "$temp_file"
fi
done < "$main_file"

issue_exist=0
while IFS= read -r line; do
if [[ $line == "Vulnerability #"* ]]; then
issue_exist=1
break
fi
done < "$temp_file"

if [ $issue_exist -eq 1 ]; then
echo "::error::One or more vulnerabilities found in packages. See detailed report."
cat "$temp_file"
exit 1
fi

0 comments on commit 2256177

Please sign in to comment.