-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add metrics #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
csv.tpl
Outdated
| {{- if isFieldAvailable "Vulnerability Class" }} | ||
| {{- printf "%s" $class | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Target Type" }} | ||
| {{- $vulnerabilityType | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Vulnerability ID" }} | ||
| {{- .VulnerabilityID | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Severity" }} | ||
| {{- .Vulnerability.Severity | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "PackageName" }} | ||
| {{- .PkgName | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Installed Version" }} | ||
| {{- .InstalledVersion | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Fixed Version" }} | ||
| {{- .FixedVersion | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Title" }} | ||
| {{- if (eq (len .Title) 0) }} | ||
| {{- printf "%s: %s - %s severity vulnerability" .PkgName .InstalledVersion .Vulnerability.Severity | escapeCsv }}, | ||
| {{- else }} | ||
| {{- abbrev 100 .Title | escapeCsv }}, | ||
| {{- end }} | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Description" }} | ||
| {{- abbrev 500 .Vulnerability.Description | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Resolution" }} | ||
| {{- if .FixedVersion }} | ||
| {{- printf "Update %s to version %s or higher." .PkgName .FixedVersion | escapeCsv }}, | ||
| {{- else }} | ||
| {{- printf "No resolution provided." | escapeCsv }}, | ||
| {{- end }} | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Reference" }} | ||
| {{- .PrimaryURL | escapeCsv }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
| {{- if isFieldAvailable "Additional Reference" }} | ||
| {{- $reference := false }} | ||
| {{- range .References }} | ||
| {{- if contains "nvd.nist.gov" . }} | ||
| {{- . | escapeCsv }} | ||
| {{- $reference = true }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- if not $reference }} | ||
| {{- printf "" | escapeCsv }} | ||
| {{- end }}, | ||
| {{- else -}} | ||
| {{- end }} | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems this template was copied from Trivy.
csv-report should implement the single feature.
so we can move any logic to main.go, the template will save the table only.
maybe simple formatting only like printf "%.1f"
main.go
Outdated
| tempTemplateFileName = "csv-report-template-temp.tpl" | ||
| templateFileName = "csv.tpl" | ||
| availableFields = []string{"Target", "Vulnerability Class", "Target Type", "Vulnerability ID", "Severity", "PackageName", "Installed Version", "Fixed Version", "Title", "Description", "Resolution", "Reference", "Additional Reference", "CVSS V3 Score", "CVSS V3 Vector"} | ||
| availableFlags = []string{"--csv-result", "--delimiter", "--include", "--exclude"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use more specific names for the flags: --csv-delimiter, --csv-include, --csv-exclude
| if availableFieldsMap["cvss v3 vector"] { | ||
| fieldValue := "" | ||
| if cvssRh.V3Vector != "" { | ||
| fieldValue = cvssNvd.V3Vector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here should be the following:
fieldValue = cvssRh.V3Vector| trivyCommand := os.Args[1 : len(os.Args)-1] | ||
| outputFileName := os.Args[len(os.Args)-1] | ||
| tempFileName := filepath.Join(os.TempDir(), tempJsonFileName) | ||
| trivyCommand := excludePluginFlags(os.Args, availableFlags)[1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now the plugin and trivy arguments can be obtained using the package github.com/afdesk/trivy-go-plugin/pkg/common
| tempTemplate, err := getChangedDelimiterTemplate() | ||
| if err != nil { | ||
| panic(err) | ||
| return "", nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is nil returned and not an error?
| if delimiter == "," { | ||
| ex, err := os.Executable() | ||
| if err != nil { | ||
| return "", nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is nil returned and not an error?
| availableFieldsMap[strings.ToLower(name)] = true | ||
| } | ||
|
|
||
| if includeFlagValue != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify this by using a single loop
var include bool
var argValue string
if includeFlagValue != "" {
include = true
argValue = includeFlagValue
} else if excludeFlagValue != "" {
include = false
argValue = excludeFlagValue
} else {
return
}
for ...
--delimitersets the delimiter, by default ",".If
--includeis specified, only the fields specified in this flag will be included.If
--excludeis specified, all fields except those specified in the flag will be shown.to specify the file in which the result will be saved, you need to specify the
--csv-resultflag--includeand--excludeflags at the same time--csv-resultis not specified, will be set the default value "result.csv"