Skip to content

Commit 55c7ba9

Browse files
committed
feat: DGP-498 - add missing legacy JSON output fields to vulnerabilities and license issues:
- credit - fixedin - is_malicious - semver - socialTrendAlert - packageManager -- from vuln or license ecosystem based on Build vs. OS discriminator Top level: - set uniqueCount from the test's effective summary Chore: - remove Go's string encoding and HTML escaping before output, for situations like "<=" in Semver. - passes a logger into transform.go for early warnings about unexpected fields
1 parent a59aa7d commit 55c7ba9

File tree

3 files changed

+450
-148
lines changed

3 files changed

+450
-148
lines changed

internal/commands/ostest/ostest.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const ForceLegacyCLIEnvVar = "SNYK_FORCE_LEGACY_CLI"
5151
// ApplicationJSONContentType matches the content type for legacy JSON findings records.
5252
const ApplicationJSONContentType = "application/json"
5353

54+
// LogFieldCount is the logger key for number of findings.
55+
const LogFieldCount = "count"
56+
5457
// ErrNoSummaryData is returned when a test summary cannot be generated due to lack of data.
5558
var ErrNoSummaryData = std_errors.New("no summary data to create")
5659

@@ -282,14 +285,14 @@ func runTest(
282285
if err != nil {
283286
logger.Error().Err(err).Msg("Error fetching findings")
284287
if !complete && len(findingsData) > 0 {
285-
logger.Warn().Int("count", len(findingsData)).Msg("Partial findings retrieved as an error occurred")
288+
logger.Warn().Int(LogFieldCount, len(findingsData)).Msg("Partial findings retrieved as an error occurred")
286289
}
287290
} else {
288291
logger.Info().Msgf("Findings count: %d\n", len(findingsData))
289292

290293
logger.Info().
291294
Bool("complete", complete).
292-
Int("count", len(findingsData)).
295+
Int(LogFieldCount, len(findingsData)).
293296
Msg("Findings fetched successfully")
294297
}
295298

@@ -300,15 +303,28 @@ func runTest(
300303
return nil, fmt.Errorf("failed to get current working directory: %w", err)
301304
}
302305

306+
var uniqueCount int32
307+
summary := finalResult.GetEffectiveSummary()
308+
if summary != nil {
309+
if summary.Count > math.MaxInt32 {
310+
uniqueCount = math.MaxInt32
311+
logger.Warn().Uint32(LogFieldCount, summary.Count).Msg("Unique finding count exceeds int32 max, capping value.")
312+
} else {
313+
uniqueCount = int32(summary.Count)
314+
}
315+
}
316+
303317
legacyJSON, err := transform.ConvertSnykSchemaFindingsToLegacyJSON(
304318
&transform.SnykSchemaToLegacyParams{
305319
Findings: findingsData,
306320
TestResult: finalResult,
307321
ProjectName: projectName,
308322
PackageManager: packageManager,
309323
CurrentDir: currentDir,
324+
UniqueCount: uniqueCount,
310325
DepCount: depCount,
311326
ErrFactory: errFactory,
327+
Logger: logger,
312328
})
313329
if err != nil {
314330
return nil, fmt.Errorf("error converting snyk schema findings to legacy json: %w", err)

0 commit comments

Comments
 (0)