1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

when downloader is run with verbose flag the advisory validation issues are logged in detail.

This commit is contained in:
Sascha L. Teichmann 2022-07-20 12:49:50 +02:00
parent 0375e22747
commit a1d609c7d8

View file

@ -191,6 +191,23 @@ func (d *downloader) loadOpenPGPKeys(
return nil
}
// logValidationIssues logs the issues reported by the advisory schema validation.
func (d *downloader) logValidationIssues(url string, errors []string, err error) {
if err != nil {
log.Printf("Failed to validate %s: %v", url, err)
return
}
if len(errors) > 0 {
if d.opts.Verbose {
log.Printf("CSAF file %s has validation errors: %s\n",
url, strings.Join(errors, ", "))
} else {
log.Printf("CSAF file %s has %d validation errors.\n",
url, len(errors))
}
}
}
func (d *downloader) downloadFiles(label csaf.TLPLabel, files []csaf.AdvisoryFile) error {
client := d.httpClient()
@ -307,13 +324,8 @@ func (d *downloader) downloadFiles(label csaf.TLPLabel, files []csaf.AdvisoryFil
}
// Validate against CSAF schema.
errors, err := csaf.ValidateCSAF(doc)
if err != nil {
log.Printf("Failed to validate %s: %v", file.URL(), err)
continue
}
if len(errors) > 0 {
log.Printf("CSAF file %s has %d validation errors.", file.URL(), len(errors))
if errors, err := csaf.ValidateCSAF(doc); err != nil || len(errors) > 0 {
d.logValidationIssues(file.URL(), errors, err)
continue
}