@@ -12,6 +12,7 @@ import (
12
12
"deps.dev/util/resolve"
13
13
"github.com/google/osv-scanner/internal/remediation"
14
14
"github.com/google/osv-scanner/internal/resolution"
15
+ "github.com/google/osv-scanner/internal/resolution/client"
15
16
lf "github.com/google/osv-scanner/internal/resolution/lockfile"
16
17
"github.com/google/osv-scanner/internal/resolution/manifest"
17
18
"github.com/google/osv-scanner/pkg/lockfile"
@@ -36,7 +37,7 @@ func autoInPlace(ctx context.Context, r reporter.Reporter, opts osvFixOptions, m
36
37
return err
37
38
}
38
39
39
- res , err := remediation .ComputeInPlacePatches (ctx , opts .Client , g , opts .RemediationOptions )
40
+ res , err := remediation .ComputeInPlacePatches (ctx , opts .Client , g , opts .Options )
40
41
if err != nil {
41
42
return err
42
43
}
@@ -57,7 +58,7 @@ func autoInPlace(ctx context.Context, r reporter.Reporter, opts osvFixOptions, m
57
58
if i > 0 {
58
59
r .Infof ("," )
59
60
}
60
- r .Infof ("%s" , v .Vulnerability .ID )
61
+ r .Infof ("%s" , v .OSV .ID )
61
62
}
62
63
r .Infof ("\n " )
63
64
@@ -72,7 +73,7 @@ func autoInPlace(ctx context.Context, r reporter.Reporter, opts osvFixOptions, m
72
73
73
74
// returns the top {maxUpgrades} compatible patches, the vulns fixed, and the number of potentially fixable vulns left unfixed
74
75
// if maxUpgrades is < 0, do as many patches as possible
75
- func autoChooseInPlacePatches (res remediation.InPlaceResult , maxUpgrades int ) ([]lf.DependencyPatch , []resolution.ResolutionVuln , int ) {
76
+ func autoChooseInPlacePatches (res remediation.InPlaceResult , maxUpgrades int ) ([]lf.DependencyPatch , []resolution.Vulnerability , int ) {
76
77
// Keep track of the VersionKeys we've already patched so we know which patches are incompatible
77
78
seenVKs := make (map [resolve.VersionKey ]bool )
78
79
@@ -83,7 +84,7 @@ func autoChooseInPlacePatches(res remediation.InPlaceResult, maxUpgrades int) ([
83
84
}
84
85
uniqueVulns := make (map [vulnKey ]struct {})
85
86
var patches []lf.DependencyPatch
86
- var fixed []resolution.ResolutionVuln
87
+ var fixed []resolution.Vulnerability
87
88
88
89
for _ , p := range res .Patches {
89
90
vk := resolve.VersionKey {
@@ -93,7 +94,7 @@ func autoChooseInPlacePatches(res remediation.InPlaceResult, maxUpgrades int) ([
93
94
94
95
// add each of the resolved vulnKeys to the set of unique vulns
95
96
for _ , rv := range p .ResolvedVulns {
96
- uniqueVulns [vulnKey {id : rv .Vulnerability .ID , vk : vk }] = struct {}{}
97
+ uniqueVulns [vulnKey {id : rv .OSV .ID , vk : vk }] = struct {}{}
97
98
}
98
99
99
100
// If we still are picking more patches, and we haven't already patched this specific version,
@@ -107,7 +108,7 @@ func autoChooseInPlacePatches(res remediation.InPlaceResult, maxUpgrades int) ([
107
108
}
108
109
109
110
// Sort the fixed vulns by ID for consistency.
110
- slices .SortFunc (fixed , func (a , b resolution.ResolutionVuln ) int { return cmp .Compare (a .Vulnerability .ID , b .Vulnerability .ID ) })
111
+ slices .SortFunc (fixed , func (a , b resolution.Vulnerability ) int { return cmp .Compare (a .OSV .ID , b .OSV .ID ) })
111
112
112
113
return patches , fixed , len (uniqueVulns ) - len (fixed )
113
114
}
@@ -129,7 +130,7 @@ func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, ma
129
130
return err
130
131
}
131
132
132
- opts . Client . PreFetch (ctx , manif .Requirements , manif .FilePath )
133
+ client . PreFetch (ctx , opts . Client , manif .Requirements , manif .FilePath )
133
134
res , err := resolution .Resolve (ctx , opts .Client , manif , opts .ResolveOpts )
134
135
if err != nil {
135
136
return err
@@ -145,7 +146,7 @@ func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, ma
145
146
totalVulns := len (res .Vulns )
146
147
r .Infof ("Found %d vulnerabilities matching the filter\n " , totalVulns )
147
148
148
- allPatches , err := remediation .ComputeRelaxPatches (ctx , opts .Client , res , opts .RemediationOptions )
149
+ allPatches , err := remediation .ComputeRelaxPatches (ctx , opts .Client , res , opts .Options )
149
150
if err != nil {
150
151
return err
151
152
}
@@ -175,7 +176,7 @@ func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, ma
175
176
if i > 0 {
176
177
r .Infof ("," )
177
178
}
178
- r .Infof ("%s" , v .Vulnerability .ID )
179
+ r .Infof ("%s" , v .OSV .ID )
179
180
}
180
181
r .Infof ("\n " )
181
182
@@ -185,7 +186,7 @@ func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, ma
185
186
// TODO: Consider potentially introduced vulnerabilities
186
187
187
188
r .Infof ("Rewriting %s...\n " , opts .Manifest )
188
- if err := manifest .Overwrite (opts .ManifestRW , opts .Manifest , manifest.ManifestPatch {Manifest : & manif , Deps : depPatches }); err != nil {
189
+ if err := manifest .Overwrite (opts .ManifestRW , opts .Manifest , manifest.Patch {Manifest : & manif , Deps : depPatches }); err != nil {
189
190
return err
190
191
}
191
192
@@ -225,10 +226,10 @@ func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, ma
225
226
226
227
// returns the top {maxUpgrades} compatible patches, and the vulns fixed
227
228
// if maxUpgrades is < 0, do as many patches as possible
228
- func autoChooseRelockPatches (diffs []resolution.ResolutionDiff , maxUpgrades int ) ([]manifest.DependencyPatch , []resolution.ResolutionVuln ) {
229
+ func autoChooseRelockPatches (diffs []resolution.Difference , maxUpgrades int ) ([]manifest.DependencyPatch , []resolution.Vulnerability ) {
229
230
var patches []manifest.DependencyPatch
230
231
pkgChanged := make (map [resolve.VersionKey ]bool ) // dependencies we've already applied a patch to
231
- var fixed []resolution.ResolutionVuln
232
+ var fixed []resolution.Vulnerability
232
233
233
234
for _ , diff := range diffs {
234
235
// If we are not picking any more patches, or this patch is incompatible with existing patches, skip adding it to the patch list.
@@ -249,27 +250,27 @@ func autoChooseRelockPatches(diffs []resolution.ResolutionDiff, maxUpgrades int)
249
250
}
250
251
251
252
// Sort the fixed vulns by ID for consistency.
252
- slices .SortFunc (fixed , func (a , b resolution.ResolutionVuln ) int { return cmp .Compare (a .Vulnerability .ID , b .Vulnerability .ID ) })
253
+ slices .SortFunc (fixed , func (a , b resolution.Vulnerability ) int { return cmp .Compare (a .OSV .ID , b .OSV .ID ) })
253
254
254
255
return patches , fixed
255
256
}
256
257
257
- func relockUnfixableVulns (diffs []resolution.ResolutionDiff ) []* resolution.ResolutionVuln {
258
+ func relockUnfixableVulns (diffs []resolution.Difference ) []* resolution.Vulnerability {
258
259
if len (diffs ) == 0 {
259
260
return nil
260
261
}
261
262
// find every vuln ID fixed in any patch
262
263
fixableVulnIDs := make (map [string ]struct {})
263
264
for _ , diff := range diffs {
264
265
for _ , v := range diff .RemovedVulns {
265
- fixableVulnIDs [v .Vulnerability .ID ] = struct {}{}
266
+ fixableVulnIDs [v .OSV .ID ] = struct {}{}
266
267
}
267
268
}
268
269
269
270
// select only vulns that aren't fixed in any patch
270
- var unfixable []* resolution.ResolutionVuln
271
+ var unfixable []* resolution.Vulnerability
271
272
for i , v := range diffs [0 ].Original .Vulns {
272
- if _ , ok := fixableVulnIDs [v .Vulnerability .ID ]; ! ok {
273
+ if _ , ok := fixableVulnIDs [v .OSV .ID ]; ! ok {
273
274
unfixable = append (unfixable , & diffs [0 ].Original .Vulns [i ])
274
275
}
275
276
}
@@ -294,7 +295,7 @@ func autoOverride(ctx context.Context, r reporter.Reporter, opts osvFixOptions,
294
295
return err
295
296
}
296
297
297
- opts . Client . PreFetch (ctx , manif .Requirements , manif .FilePath )
298
+ client . PreFetch (ctx , opts . Client , manif .Requirements , manif .FilePath )
298
299
res , err := resolution .Resolve (ctx , opts .Client , manif , opts .ResolveOpts )
299
300
if err != nil {
300
301
return err
@@ -310,7 +311,7 @@ func autoOverride(ctx context.Context, r reporter.Reporter, opts osvFixOptions,
310
311
totalVulns := len (res .Vulns )
311
312
r .Infof ("Found %d vulnerabilities matching the filter\n " , totalVulns )
312
313
313
- allPatches , err := remediation .ComputeOverridePatches (ctx , opts .Client , res , opts .RemediationOptions )
314
+ allPatches , err := remediation .ComputeOverridePatches (ctx , opts .Client , res , opts .Options )
314
315
if err != nil {
315
316
return err
316
317
}
@@ -340,7 +341,7 @@ func autoOverride(ctx context.Context, r reporter.Reporter, opts osvFixOptions,
340
341
if i > 0 {
341
342
r .Infof ("," )
342
343
}
343
- r .Infof ("%s" , v .Vulnerability .ID )
344
+ r .Infof ("%s" , v .OSV .ID )
344
345
}
345
346
r .Infof ("\n " )
346
347
@@ -350,21 +351,21 @@ func autoOverride(ctx context.Context, r reporter.Reporter, opts osvFixOptions,
350
351
// TODO: Consider potentially introduced vulnerabilities
351
352
352
353
r .Infof ("Rewriting %s...\n " , opts .Manifest )
353
- if err := manifest .Overwrite (opts .ManifestRW , opts .Manifest , manifest.ManifestPatch {Manifest : & manif , Deps : depPatches }); err != nil {
354
+ if err := manifest .Overwrite (opts .ManifestRW , opts .Manifest , manifest.Patch {Manifest : & manif , Deps : depPatches }); err != nil {
354
355
return err
355
356
}
356
357
357
358
return nil
358
359
}
359
360
360
- func autoChooseOverridePatches (diffs []resolution.ResolutionDiff , maxUpgrades int ) ([]manifest.DependencyPatch , []resolution.ResolutionVuln ) {
361
+ func autoChooseOverridePatches (diffs []resolution.Difference , maxUpgrades int ) ([]manifest.DependencyPatch , []resolution.Vulnerability ) {
361
362
if maxUpgrades == 0 {
362
363
return nil , nil
363
364
}
364
365
365
366
var patches []manifest.DependencyPatch
366
- pkgChanged := make (map [resolve.PackageKey ]bool ) // dependencies we've already applied a patch to
367
- fixedVulns := make (map [string ]resolution.ResolutionVuln ) // vulns that have already been fixed by a patch
367
+ pkgChanged := make (map [resolve.PackageKey ]bool ) // dependencies we've already applied a patch to
368
+ fixedVulns := make (map [string ]resolution.Vulnerability ) // vulns that have already been fixed by a patch
368
369
for _ , diff := range diffs {
369
370
// If this patch is incompatible with existing patches, skip adding it to the patch list.
370
371
@@ -377,7 +378,7 @@ func autoChooseOverridePatches(diffs []resolution.ResolutionDiff, maxUpgrades in
377
378
// e.g. We have {foo@1 -> bar@1}, and two possible patches [foo@3, bar@2].
378
379
// Patching foo@3 makes {foo@3 -> bar@3}, which also fixes the vulnerability in bar.
379
380
// Applying both patches would force {foo@3 -> bar@2}, which is less desirable.
380
- if slices .ContainsFunc (diff .RemovedVulns , func (rv resolution.ResolutionVuln ) bool { _ , ok := fixedVulns [rv .Vulnerability .ID ]; return ok }) {
381
+ if slices .ContainsFunc (diff .RemovedVulns , func (rv resolution.Vulnerability ) bool { _ , ok := fixedVulns [rv .OSV .ID ]; return ok }) {
381
382
continue
382
383
}
383
384
@@ -387,7 +388,7 @@ func autoChooseOverridePatches(diffs []resolution.ResolutionDiff, maxUpgrades in
387
388
pkgChanged [dp .Pkg ] = true
388
389
}
389
390
for _ , rv := range diff .RemovedVulns {
390
- fixedVulns [rv .Vulnerability .ID ] = rv
391
+ fixedVulns [rv .OSV .ID ] = rv
391
392
}
392
393
393
394
maxUpgrades --
@@ -398,13 +399,13 @@ func autoChooseOverridePatches(diffs []resolution.ResolutionDiff, maxUpgrades in
398
399
399
400
// Sort the fixed vulns by ID for consistency.
400
401
fixed := maps .Values (fixedVulns )
401
- slices .SortFunc (fixed , func (a , b resolution.ResolutionVuln ) int { return cmp .Compare (a .Vulnerability .ID , b .Vulnerability .ID ) })
402
+ slices .SortFunc (fixed , func (a , b resolution.Vulnerability ) int { return cmp .Compare (a .OSV .ID , b .OSV .ID ) })
402
403
403
404
return patches , fixed
404
405
}
405
406
406
- func resolutionErrorString (res * resolution.ResolutionResult , errs []resolution.ResolutionError ) string {
407
- // we pass in the []ResolutionErrors because calling res.Errors() is costly
407
+ func resolutionErrorString (res * resolution.Result , errs []resolution.NodeError ) string {
408
+ // we pass in the []resolution.NodeError because calling res.Errors() is costly
408
409
s := strings.Builder {}
409
410
for _ , e := range errs {
410
411
node := res .Graph .Nodes [e .NodeID ]
0 commit comments