Skip to content

Commit 84691b4

Browse files
authored
refactor: Switch to use public osvdev client (#1804)
And delete the osvdev package in this repository.
1 parent 6da7d11 commit 84691b4

16 files changed

Lines changed: 23 additions & 1014 deletions

File tree

cmd/osv-scanner/fix/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/google/osv-scanner/v2/internal/cmdlogger"
1717
"github.com/google/osv-scanner/v2/internal/depsdev"
1818
"github.com/google/osv-scanner/v2/internal/imodels/ecosystem"
19-
"github.com/google/osv-scanner/v2/internal/osvdev"
2019
"github.com/google/osv-scanner/v2/internal/remediation"
2120
"github.com/google/osv-scanner/v2/internal/remediation/upgrade"
2221
"github.com/google/osv-scanner/v2/internal/resolution"
@@ -27,6 +26,7 @@ import (
2726
"github.com/google/osv-scanner/v2/internal/version"
2827
"github.com/urfave/cli/v2"
2928
"golang.org/x/term"
29+
"osv.dev/bindings/go/osvdev"
3030
)
3131

3232
type strategy string

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/jedib0t/go-pretty/v6 v6.6.7
2323
github.com/muesli/reflow v0.3.0
2424
github.com/opencontainers/go-digest v1.0.0
25-
github.com/ossf/osv-schema/bindings/go v0.0.0-20250318011049-e4c58d9a4a9e
25+
github.com/ossf/osv-schema/bindings/go v0.0.0-20250401015358-964c89294a70
2626
github.com/owenrumney/go-sarif/v2 v2.3.3
2727
github.com/package-url/packageurl-go v0.1.3
2828
github.com/pandatix/go-cvss v0.6.2
@@ -31,13 +31,14 @@ require (
3131
github.com/tidwall/sjson v1.2.5
3232
github.com/urfave/cli/v2 v2.27.6
3333
golang.org/x/net v0.38.0
34-
golang.org/x/sync v0.12.0
34+
golang.org/x/sync v0.13.0
3535
golang.org/x/term v0.30.0
3636
golang.org/x/vuln v1.1.3
3737
google.golang.org/grpc v1.71.0
3838
google.golang.org/protobuf v1.36.6
3939
gopkg.in/ini.v1 v1.67.0
4040
gopkg.in/yaml.v3 v3.0.1
41+
osv.dev/bindings/go v0.0.0-20250411041304-d50b498021fc
4142
)
4243

4344
require (

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bl
276276
github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
277277
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
278278
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
279-
github.com/ossf/osv-schema/bindings/go v0.0.0-20250318011049-e4c58d9a4a9e h1:v/bSQI7UNOcg2i6iEtVKSQNSckOxutSrt8aYEHQobLU=
280-
github.com/ossf/osv-schema/bindings/go v0.0.0-20250318011049-e4c58d9a4a9e/go.mod h1:lILztSxHU7VsdlYqCnwgxSDBhbXMf7iEQWtldJCDXPo=
279+
github.com/ossf/osv-schema/bindings/go v0.0.0-20250401015358-964c89294a70 h1:uIRWzcJre+A+QgI7YWPsHraSD77LXVHUnsYZawjhqas=
280+
github.com/ossf/osv-schema/bindings/go v0.0.0-20250401015358-964c89294a70/go.mod h1:lILztSxHU7VsdlYqCnwgxSDBhbXMf7iEQWtldJCDXPo=
281281
github.com/owenrumney/go-sarif v1.1.1/go.mod h1:dNDiPlF04ESR/6fHlPyq7gHKmrM0sHUvAGjsoh8ZH0U=
282282
github.com/owenrumney/go-sarif/v2 v2.3.3 h1:ubWDJcF5i3L/EIOER+ZyQ03IfplbSU1BLOE26uKQIIU=
283283
github.com/owenrumney/go-sarif/v2 v2.3.3/go.mod h1:MSqMMx9WqlBSY7pXoOZWgEsVB4FDNfhcaXDA1j6Sr+w=
@@ -442,8 +442,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
442442
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
443443
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
444444
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
445-
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
446-
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
445+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
446+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
447447
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
448448
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
449449
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -554,6 +554,8 @@ modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
554554
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
555555
modernc.org/sqlite v1.20.3 h1:SqGJMMxjj1PHusLxdYxeQSodg7Jxn9WWkaAQjKrntZs=
556556
modernc.org/sqlite v1.20.3/go.mod h1:zKcGyrICaxNTMEHSr1HQ2GUraP0j+845GYw37+EyT6A=
557+
osv.dev/bindings/go v0.0.0-20250411041304-d50b498021fc h1:Gu06XS+AvIwpePuOhkZ2Wgbd23M45k1JrtNtNXFf9YQ=
558+
osv.dev/bindings/go v0.0.0-20250411041304-d50b498021fc/go.mod h1:svwlXlXiK7mfdhDO0SXkM36wgXxT+0d71ncYc2oBlQ8=
557559
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
558560
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
559561
www.velocidex.com/golang/regparser v0.0.0-20240404115756-2169ac0e3c09 h1:G1RWYBXP2lSzxKcrAU1YhiUlBetZ7hGIzIiWuuazvfo=

internal/clients/clientimpl/osvmatcher/cachedosvmatcher.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"github.com/google/osv-scalibr/extractor"
1212
"github.com/google/osv-scanner/v2/internal/clients/clientimpl/localmatcher"
1313
"github.com/google/osv-scanner/v2/internal/imodels"
14-
"github.com/google/osv-scanner/v2/internal/osvdev"
1514
"github.com/ossf/osv-schema/bindings/go/osvschema"
1615
"golang.org/x/sync/errgroup"
16+
"osv.dev/bindings/go/osvdev"
17+
"osv.dev/bindings/go/osvdevexperimental"
1718
)
1819

1920
// CachedOSVMatcher implements the VulnerabilityMatcher interface with a osv.dev client.
@@ -94,10 +95,10 @@ func (matcher *CachedOSVMatcher) doQueries(ctx context.Context, invs []*extracto
9495
// If there is a timeout for the initial query, set an additional context deadline here.
9596
if matcher.InitialQueryTimeout > 0 {
9697
batchQueryCtx, cancelFunc := context.WithDeadline(ctx, time.Now().Add(matcher.InitialQueryTimeout))
97-
batchResp, err = queryForBatchWithPaging(batchQueryCtx, &matcher.Client, queries)
98+
batchResp, err = osvdevexperimental.BatchQueryPaging(batchQueryCtx, &matcher.Client, queries)
9899
cancelFunc()
99100
} else {
100-
batchResp, err = queryForBatchWithPaging(ctx, &matcher.Client, queries)
101+
batchResp, err = osvdevexperimental.BatchQueryPaging(ctx, &matcher.Client, queries)
101102
}
102103

103104
if err != nil {

internal/clients/clientimpl/osvmatcher/errors.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

internal/clients/clientimpl/osvmatcher/osvmatcher.go

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"github.com/google/osv-scalibr/extractor"
99
"github.com/google/osv-scalibr/log"
1010
"github.com/google/osv-scanner/v2/internal/imodels"
11-
"github.com/google/osv-scanner/v2/internal/osvdev"
1211
"github.com/ossf/osv-schema/bindings/go/osvschema"
1312
"golang.org/x/sync/errgroup"
13+
"osv.dev/bindings/go/osvdev"
14+
"osv.dev/bindings/go/osvdevexperimental"
1415
)
1516

1617
const (
@@ -39,10 +40,10 @@ func (matcher *OSVMatcher) MatchVulnerabilities(ctx context.Context, pkgs []*ext
3940
// If there is a timeout for the initial query, set an additional context deadline here.
4041
if matcher.InitialQueryTimeout > 0 {
4142
batchQueryCtx, cancelFunc := context.WithDeadline(ctx, time.Now().Add(matcher.InitialQueryTimeout))
42-
batchResp, err = queryForBatchWithPaging(batchQueryCtx, &matcher.Client, queries)
43+
batchResp, err = osvdevexperimental.BatchQueryPaging(batchQueryCtx, &matcher.Client, queries)
4344
cancelFunc()
4445
} else {
45-
batchResp, err = queryForBatchWithPaging(ctx, &matcher.Client, queries)
46+
batchResp, err = osvdevexperimental.BatchQueryPaging(ctx, &matcher.Client, queries)
4647
}
4748

4849
if err != nil {
@@ -92,65 +93,6 @@ func (matcher *OSVMatcher) MatchVulnerabilities(ctx context.Context, pkgs []*ext
9293
return vulnerabilities, nil
9394
}
9495

95-
func queryForBatchWithPaging(ctx context.Context, c *osvdev.OSVClient, queries []*osvdev.Query) (*osvdev.BatchedResponse, error) {
96-
batchResp, err := c.QueryBatch(ctx, queries)
97-
98-
if err != nil {
99-
return nil, err
100-
}
101-
// --- Paging logic ---
102-
var errToReturn error
103-
nextPageQueries := []*osvdev.Query{}
104-
nextPageIndexMap := []int{}
105-
for i, res := range batchResp.Results {
106-
if res.NextPageToken == "" {
107-
continue
108-
}
109-
110-
query := *queries[i]
111-
query.PageToken = res.NextPageToken
112-
nextPageQueries = append(nextPageQueries, &query)
113-
nextPageIndexMap = append(nextPageIndexMap, i)
114-
}
115-
116-
if len(nextPageQueries) > 0 {
117-
// If context is cancelled or deadline exceeded, return now
118-
if ctx.Err() != nil {
119-
return batchResp, &DuringPagingError{
120-
PageDepth: 1,
121-
Inner: ctx.Err(),
122-
}
123-
}
124-
125-
nextPageResp, err := queryForBatchWithPaging(ctx, c, nextPageQueries)
126-
if err != nil {
127-
var dpr *DuringPagingError
128-
if ok := errors.As(err, &dpr); ok {
129-
dpr.PageDepth += 1
130-
errToReturn = dpr
131-
} else {
132-
errToReturn = &DuringPagingError{
133-
PageDepth: 1,
134-
Inner: err,
135-
}
136-
}
137-
}
138-
139-
// Whether there is an error or not, if there is any data,
140-
// we want to save and return what we got.
141-
if nextPageResp != nil {
142-
for i, res := range nextPageResp.Results {
143-
batchResp.Results[nextPageIndexMap[i]].Vulns = append(batchResp.Results[nextPageIndexMap[i]].Vulns, res.Vulns...)
144-
// Set next page token so caller knows whether this is all the results
145-
// even if it is being cancelled.
146-
batchResp.Results[nextPageIndexMap[i]].NextPageToken = res.NextPageToken
147-
}
148-
}
149-
}
150-
151-
return batchResp, errToReturn
152-
}
153-
15496
func pkgToQuery(pkg imodels.PackageInfo) *osvdev.Query {
15597
if pkg.Name() != "" && !pkg.Ecosystem().IsEmpty() && pkg.Version() != "" {
15698
return &osvdev.Query{

internal/osvdev/config.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

internal/osvdev/models.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)