save progress
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Routing;
|
||||
using StellaOps.Scanner.SmartDiff.Detection;
|
||||
using StellaOps.Scanner.SmartDiff.Output;
|
||||
using StellaOps.Scanner.Storage.Postgres;
|
||||
using StellaOps.Scanner.WebService.Services;
|
||||
using StellaOps.Scanner.WebService.Security;
|
||||
|
||||
namespace StellaOps.Scanner.WebService.Endpoints;
|
||||
@@ -80,7 +81,7 @@ internal static class SmartDiffEndpoints
|
||||
// Get scan metadata if available
|
||||
string? baseDigest = null;
|
||||
string? targetDigest = null;
|
||||
DateTimeOffset scanTime = DateTimeOffset.UtcNow;
|
||||
DateTimeOffset scanTime = DateTimeOffset.UnixEpoch;
|
||||
|
||||
if (metadataRepo is not null)
|
||||
{
|
||||
@@ -99,13 +100,16 @@ internal static class SmartDiffEndpoints
|
||||
ScanTime: scanTime,
|
||||
BaseDigest: baseDigest,
|
||||
TargetDigest: targetDigest,
|
||||
MaterialChanges: changes.Select(c => new MaterialRiskChange(
|
||||
VulnId: c.VulnId,
|
||||
ComponentPurl: c.ComponentPurl,
|
||||
Direction: c.IsRiskIncrease ? RiskDirection.Increased : RiskDirection.Decreased,
|
||||
Reason: c.ChangeReason,
|
||||
FilePath: c.FilePath
|
||||
)).ToList(),
|
||||
MaterialChanges: changes
|
||||
.Where(c => c.HasMaterialChange)
|
||||
.Select(c => new MaterialRiskChange(
|
||||
VulnId: c.FindingKey.VulnId,
|
||||
ComponentPurl: c.FindingKey.ComponentPurl,
|
||||
Direction: ToSarifRiskDirection(c),
|
||||
Reason: ToSarifReason(c),
|
||||
FilePath: null
|
||||
))
|
||||
.ToList(),
|
||||
HardeningRegressions: [],
|
||||
VexCandidates: [],
|
||||
ReachabilityChanges: []);
|
||||
@@ -120,7 +124,7 @@ internal static class SmartDiffEndpoints
|
||||
};
|
||||
|
||||
var generator = new SarifOutputGenerator();
|
||||
var sarifJson = generator.Generate(sarifInput, options);
|
||||
var sarifJson = generator.GenerateJson(sarifInput, options);
|
||||
|
||||
// Return as SARIF content type with proper filename
|
||||
var fileName = $"smartdiff-{scanId}.sarif";
|
||||
@@ -130,6 +134,46 @@ internal static class SmartDiffEndpoints
|
||||
statusCode: StatusCodes.Status200OK);
|
||||
}
|
||||
|
||||
private static StellaOps.Scanner.SmartDiff.Output.RiskDirection ToSarifRiskDirection(MaterialRiskChangeResult change)
|
||||
{
|
||||
if (change.Changes.IsDefaultOrEmpty)
|
||||
{
|
||||
return StellaOps.Scanner.SmartDiff.Output.RiskDirection.Changed;
|
||||
}
|
||||
|
||||
var hasIncreased = change.Changes.Any(c => c.Direction == StellaOps.Scanner.SmartDiff.Detection.RiskDirection.Increased);
|
||||
var hasDecreased = change.Changes.Any(c => c.Direction == StellaOps.Scanner.SmartDiff.Detection.RiskDirection.Decreased);
|
||||
|
||||
return (hasIncreased, hasDecreased) switch
|
||||
{
|
||||
(true, false) => StellaOps.Scanner.SmartDiff.Output.RiskDirection.Increased,
|
||||
(false, true) => StellaOps.Scanner.SmartDiff.Output.RiskDirection.Decreased,
|
||||
_ => StellaOps.Scanner.SmartDiff.Output.RiskDirection.Changed
|
||||
};
|
||||
}
|
||||
|
||||
private static string ToSarifReason(MaterialRiskChangeResult change)
|
||||
{
|
||||
if (change.Changes.IsDefaultOrEmpty)
|
||||
{
|
||||
return "material_change";
|
||||
}
|
||||
|
||||
var reasons = change.Changes
|
||||
.Select(c => c.Reason)
|
||||
.Where(r => !string.IsNullOrWhiteSpace(r))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.Order(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
return reasons.Length switch
|
||||
{
|
||||
0 => "material_change",
|
||||
1 => reasons[0],
|
||||
_ => string.Join("; ", reasons)
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetScannerVersion()
|
||||
{
|
||||
var assembly = typeof(SmartDiffEndpoints).Assembly;
|
||||
@@ -289,7 +333,7 @@ internal static class SmartDiffEndpoints
|
||||
};
|
||||
}
|
||||
|
||||
private static VexCandidateDto ToCandidateDto(VexCandidate candidate)
|
||||
private static VexCandidateDto ToCandidateDto(StellaOps.Scanner.SmartDiff.Detection.VexCandidate candidate)
|
||||
{
|
||||
return new VexCandidateDto
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user