-
Notifications
You must be signed in to change notification settings - Fork 363
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
fix(offline): report all ecosystems without local databases in one single line #1279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import ( | |
"fmt" | ||
"os" | ||
"path" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/google/osv-scanner/pkg/lockfile" | ||
"github.com/google/osv-scanner/pkg/models" | ||
|
@@ -116,6 +118,9 @@ func MakeRequest(r reporter.Reporter, query osv.BatchedQuery, offline bool, loca | |
return db, nil | ||
} | ||
|
||
// slice to track ecosystems that did not have an offline database available | ||
var missingDbs []string | ||
|
||
for _, query := range query.Queries { | ||
pkg, err := toPackageDetails(query) | ||
|
||
|
@@ -143,8 +148,13 @@ func MakeRequest(r reporter.Reporter, query osv.BatchedQuery, offline bool, loca | |
db, err := loadDBFromCache(pkg.Ecosystem) | ||
|
||
if err != nil { | ||
// currently, this will actually only error if the PURL cannot be parses | ||
r.Errorf("could not load db for %s ecosystem: %v\n", pkg.Ecosystem, err) | ||
if errors.Is(err, ErrOfflineDatabaseNotFound) { | ||
missingDbs = append(missingDbs, string(pkg.Ecosystem)) | ||
} else { | ||
// the most likely error at this point is that the PURL could not be parsed | ||
r.Errorf("could not load db for %s ecosystem: %v\n", pkg.Ecosystem, err) | ||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this no longer has coverage, but that's fine while my comment mentions a possible error being a PURL could not be parsed, we've not got a test for that and I'm not sure how easy it'll be - I've made a note to look into that as a separate thing, but we shouldn't let it block this as I think we want to be playing it safe i.e. by logging the error rather than assume the only possible error could be that the database cannot be found |
||
} | ||
|
||
results = append(results, osv.Response{Vulns: []models.Vulnerability{}}) | ||
|
||
continue | ||
|
@@ -153,5 +163,12 @@ func MakeRequest(r reporter.Reporter, query osv.BatchedQuery, offline bool, loca | |
results = append(results, osv.Response{Vulns: db.VulnerabilitiesAffectingPackage(pkg)}) | ||
} | ||
|
||
if len(missingDbs) > 0 { | ||
missingDbs = slices.Compact(missingDbs) | ||
slices.Sort(missingDbs) | ||
|
||
r.Errorf("could not find local databases for ecosystems: %s\n", strings.Join(missingDbs, ", ")) | ||
} | ||
|
||
return &osv.HydratedBatchedResponse{Results: results}, 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.
note: I've had to put this in a dedicated test because our other local db tests try to reuse the database as an optimization when run locally, which is exactly what we don't want here