■ ■ ■ ■ ■ ■
cron/internal/worker/main.go
| skipped 42 lines |
43 | 43 | | "github.com/ossf/scorecard/v4/stats" |
44 | 44 | | ) |
45 | 45 | | |
| 46 | + | const ( |
| 47 | + | resultsFile = "results.json" |
| 48 | + | rawResultsFile = "raw.json" |
| 49 | + | ) |
| 50 | + | |
46 | 51 | | var ignoreRuntimeErrors = flag.Bool("ignoreRuntimeErrors", false, "if set to true any runtime errors will be ignored") |
47 | 52 | | |
48 | 53 | | // nolint: gocognit |
49 | 54 | | func processRequest(ctx context.Context, |
50 | 55 | | batchRequest *data.ScorecardBatchRequest, |
51 | | - | blacklistedChecks []string, bucketURL, rawBucketURL, exportBucketURL string, |
| 56 | + | blacklistedChecks []string, bucketURL, rawBucketURL, apiBucketURL string, |
52 | 57 | | checkDocs docs.Doc, |
53 | 58 | | repoClient clients.RepoClient, ossFuzzRepoClient clients.RepoClient, |
54 | 59 | | ciiClient clients.CIIBestPracticesClient, |
| skipped 84 lines |
139 | 144 | | if err := format.AsRawJSON(&result, &exportRawBuffer); err != nil { |
140 | 145 | | return fmt.Errorf("error during result.AsRawJSON for export: %w", err) |
141 | 146 | | } |
142 | | - | exportPath := fmt.Sprintf("%s/result.json", repo.URI()) |
143 | | - | exportCommitSHAPath := fmt.Sprintf("%s/%s/result.json", repo.URI(), result.Repo.CommitSHA) |
144 | | - | exportRawPath := fmt.Sprintf("%s/raw.json", repo.URI()) |
145 | | - | exportRawCommitSHAPath := fmt.Sprintf("%s/%s/raw.json", repo.URI(), result.Repo.CommitSHA) |
| 147 | + | exportPath := fmt.Sprintf("%s/%s", repo.URI(), resultsFile) |
| 148 | + | exportCommitSHAPath := fmt.Sprintf("%s/%s/%s", repo.URI(), result.Repo.CommitSHA, resultsFile) |
| 149 | + | exportRawPath := fmt.Sprintf("%s/%s", repo.URI(), rawResultsFile) |
| 150 | + | exportRawCommitSHAPath := fmt.Sprintf("%s/%s/%s", repo.URI(), result.Repo.CommitSHA, rawResultsFile) |
146 | 151 | | |
147 | 152 | | // Raw result. |
148 | 153 | | if err := format.AsRawJSON(&result, &rawBuffer); err != nil { |
| skipped 1 lines |
150 | 155 | | } |
151 | 156 | | |
152 | 157 | | // These are results without the commit SHA which represents the latest commit. |
153 | | - | if err := data.WriteToBlobStore(ctx, exportBucketURL, exportPath, exportBuffer.Bytes()); err != nil { |
| 158 | + | if err := data.WriteToBlobStore(ctx, apiBucketURL, exportPath, exportBuffer.Bytes()); err != nil { |
154 | 159 | | return fmt.Errorf("error during writing to exportBucketURL: %w", err) |
155 | 160 | | } |
156 | 161 | | // Export result based on commitSHA. |
157 | | - | if err := data.WriteToBlobStore(ctx, exportBucketURL, exportCommitSHAPath, exportBuffer.Bytes()); err != nil { |
| 162 | + | if err := data.WriteToBlobStore(ctx, apiBucketURL, exportCommitSHAPath, exportBuffer.Bytes()); err != nil { |
158 | 163 | | return fmt.Errorf("error during exportBucketURL with commit SHA: %w", err) |
159 | 164 | | } |
160 | 165 | | // Export raw result. |
161 | | - | if err := data.WriteToBlobStore(ctx, exportBucketURL, exportRawPath, exportRawBuffer.Bytes()); err != nil { |
| 166 | + | if err := data.WriteToBlobStore(ctx, apiBucketURL, exportRawPath, exportRawBuffer.Bytes()); err != nil { |
162 | 167 | | return fmt.Errorf("error during writing to exportBucketURL for raw results: %w", err) |
163 | 168 | | } |
164 | | - | if err := data.WriteToBlobStore(ctx, exportBucketURL, exportRawCommitSHAPath, exportRawBuffer.Bytes()); err != nil { |
| 169 | + | if err := data.WriteToBlobStore(ctx, apiBucketURL, exportRawCommitSHAPath, exportRawBuffer.Bytes()); err != nil { |
165 | 170 | | return fmt.Errorf("error during exportBucketURL for raw results with commit SHA: %w", err) |
166 | 171 | | } |
167 | 172 | | } |
| skipped 70 lines |
238 | 243 | | panic(err) |
239 | 244 | | } |
240 | 245 | | |
241 | | - | exportBucketURL, err := config.GetBQExportResultsBucketURL() |
| 246 | + | apiBucketURL, err := config.GetAPIResultsBucketURL() |
242 | 247 | | if err != nil { |
243 | 248 | | panic(err) |
244 | 249 | | } |
| skipped 33 lines |
278 | 283 | | break |
279 | 284 | | } |
280 | 285 | | if err := processRequest(ctx, req, blacklistedChecks, |
281 | | - | bucketURL, rawBucketURL, exportBucketURL, checkDocs, |
| 286 | + | bucketURL, rawBucketURL, apiBucketURL, checkDocs, |
282 | 287 | | repoClient, ossFuzzRepoClient, ciiClient, vulnsClient, logger); err != nil { |
283 | 288 | | // TODO(log): Previously Warn. Consider logging an error here. |
284 | 289 | | logger.Info(fmt.Sprintf("error processing request: %v", err)) |
| skipped 14 lines |