@@ -44,6 +44,7 @@ func main() {
44
44
debianOutputPath := flag .String ("output_path" , debianOutputPathDefault , "Path to output OSV files." )
45
45
outputBucketName := flag .String ("output_bucket" , outputBucketDefault , "The GCS bucket to write to." )
46
46
numWorkers := flag .Int ("num_workers" , 64 , "Number of workers to process records" )
47
+ uploadToGCS := flag .Bool ("uploadToGCS" , false , "If true, do not write to GCS bucket and instead write to local disk." )
47
48
flag .Parse ()
48
49
49
50
err := os .MkdirAll (* debianOutputPath , 0755 )
@@ -64,11 +65,14 @@ func main() {
64
65
allCVEs := vulns .LoadAllCVEs (defaultCvePath )
65
66
66
67
ctx := context .Background ()
67
- storageClient , err := storage .NewClient (ctx )
68
- if err != nil {
69
- logger .Fatal ("Failed to create storage client" , slog .Any ("err" , err ))
68
+ var bkt * storage.BucketHandle
69
+ if * uploadToGCS {
70
+ storageClient , err := storage .NewClient (ctx )
71
+ if err != nil {
72
+ logger .Fatal ("Failed to create storage client" , slog .Any ("err" , err ))
73
+ }
74
+ bkt = storageClient .Bucket (* outputBucketName )
70
75
}
71
- bkt := storageClient .Bucket (* outputBucketName )
72
76
73
77
var wg sync.WaitGroup
74
78
vulnChan := make (chan * vulns.Vulnerability )
@@ -97,6 +101,7 @@ func main() {
97
101
}
98
102
99
103
func worker (ctx context.Context , vulnChan <- chan * vulns.Vulnerability , bkt * storage.BucketHandle , outputDir string ) {
104
+ noUpload := bkt == nil
100
105
for v := range vulnChan {
101
106
debianID := v .ID
102
107
if len (v .Affected ) == 0 {
@@ -111,10 +116,26 @@ func worker(ctx context.Context, vulnChan <-chan *vulns.Vulnerability, bkt *stor
111
116
continue
112
117
}
113
118
119
+ objName := path .Join (outputDir , debianID + ".json" )
120
+
121
+ if noUpload {
122
+ logger .Info ("Writing to local disk" , slog .String ("path" , objName ))
123
+ v .Modified = time .Now ().UTC ()
124
+ buf , err = json .MarshalIndent (v , "" , " " )
125
+ if err != nil {
126
+ logger .Error ("failed to marshal vulnerability with modified time" , slog .String ("id" , debianID ), slog .Any ("err" , err ))
127
+ continue
128
+ }
129
+ if err := os .WriteFile (objName , buf , 0600 ); err != nil {
130
+ logger .Error ("failed to write file in dry run" , slog .String ("path" , objName ), slog .Any ("err" , err ))
131
+ }
132
+
133
+ continue
134
+ }
135
+
114
136
hash := sha256 .Sum256 (buf )
115
137
hexHash := hex .EncodeToString (hash [:])
116
138
117
- objName := path .Join (outputDir , debianID + ".json" )
118
139
obj := bkt .Object (objName )
119
140
120
141
// Check if object exists and if hash matches.
@@ -237,7 +258,9 @@ func generateOSVFromDebianTracker(debianData DebianSecurityTrackerData, debianRe
237
258
}
238
259
239
260
if release .Status == "resolved" {
240
- pkgInfo .VersionInfo .AffectedVersions = []models.AffectedVersion {{Fixed : release .FixedVersion }}
261
+ pkgInfo .VersionInfo .AffectedVersions = []models.AffectedVersion {{Introduced : "0" }, {Fixed : release .FixedVersion }}
262
+ } else {
263
+ pkgInfo .VersionInfo .AffectedVersions = []models.AffectedVersion {{Introduced : "0" }}
241
264
}
242
265
243
266
if len (pkgInfo .VersionInfo .AffectedVersions ) > 0 {
0 commit comments