save work
This commit is contained in:
@@ -394,26 +394,59 @@ internal sealed class RuntimeInventoryReconciler : IRuntimeInventoryReconciler
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var options = _storageOptions.CurrentValue;
|
||||
var key = ArtifactObjectKeyBuilder.Build(
|
||||
|
||||
var primaryKey = ArtifactObjectKeyBuilder.Build(
|
||||
artifact.Type,
|
||||
artifact.Format,
|
||||
artifact.BytesSha256,
|
||||
options.ObjectStore.RootPrefix);
|
||||
|
||||
var descriptor = new ArtifactObjectDescriptor(
|
||||
options.ObjectStore.BucketName,
|
||||
key,
|
||||
artifact.Immutable);
|
||||
var candidates = new List<string>
|
||||
{
|
||||
primaryKey,
|
||||
ArtifactObjectKeyBuilder.Build(
|
||||
artifact.Type,
|
||||
artifact.Format,
|
||||
artifact.BytesSha256,
|
||||
rootPrefix: null)
|
||||
};
|
||||
|
||||
var legacyDigest = NormalizeLegacyDigest(artifact.BytesSha256);
|
||||
candidates.Add($"{MapLegacyTypeSegment(artifact.Type)}/{MapLegacyFormatSegment(artifact.Format)}/{legacyDigest}");
|
||||
|
||||
if (legacyDigest.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
candidates.Add($"{MapLegacyTypeSegment(artifact.Type)}/{MapLegacyFormatSegment(artifact.Format)}/{legacyDigest["sha256:".Length..]}");
|
||||
}
|
||||
|
||||
Stream? stream = null;
|
||||
string? resolvedKey = null;
|
||||
|
||||
foreach (var candidateKey in candidates.Distinct(StringComparer.Ordinal))
|
||||
{
|
||||
var descriptor = new ArtifactObjectDescriptor(
|
||||
options.ObjectStore.BucketName,
|
||||
candidateKey,
|
||||
artifact.Immutable);
|
||||
|
||||
stream = await _objectStore.GetAsync(descriptor, cancellationToken).ConfigureAwait(false);
|
||||
if (stream is not null)
|
||||
{
|
||||
resolvedKey = candidateKey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await using var stream = await _objectStore.GetAsync(descriptor, cancellationToken).ConfigureAwait(false);
|
||||
if (stream is null)
|
||||
{
|
||||
_logger.LogWarning("SBOM artifact content not found at {Key}", key);
|
||||
_logger.LogWarning("SBOM artifact content not found at {Key}", primaryKey);
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await using (stream)
|
||||
{
|
||||
var bom = await Serializer.DeserializeAsync(stream).ConfigureAwait(false);
|
||||
if (bom?.Components is null)
|
||||
{
|
||||
@@ -435,10 +468,11 @@ internal sealed class RuntimeInventoryReconciler : IRuntimeInventoryReconciler
|
||||
FilePaths = ExtractFilePaths(c)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to deserialize SBOM from artifact {ArtifactId}", artifact.Id);
|
||||
_logger.LogWarning(ex, "Failed to deserialize SBOM from artifact {ArtifactId} ({ResolvedKey})", artifact.Id, resolvedKey ?? primaryKey);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -595,6 +629,38 @@ internal sealed class RuntimeInventoryReconciler : IRuntimeInventoryReconciler
|
||||
return trimmed.ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static string NormalizeLegacyDigest(string digest)
|
||||
=> digest.Contains(':', StringComparison.Ordinal)
|
||||
? digest.Trim()
|
||||
: $"sha256:{digest.Trim()}";
|
||||
|
||||
private static string MapLegacyTypeSegment(ArtifactDocumentType type) => type switch
|
||||
{
|
||||
ArtifactDocumentType.LayerBom => "layerbom",
|
||||
ArtifactDocumentType.ImageBom => "imagebom",
|
||||
ArtifactDocumentType.Index => "index",
|
||||
ArtifactDocumentType.Attestation => "attestation",
|
||||
ArtifactDocumentType.SurfaceManifest => "surface-manifest",
|
||||
ArtifactDocumentType.SurfaceEntryTrace => "surface-entrytrace",
|
||||
ArtifactDocumentType.SurfaceLayerFragment => "surface-layer-fragment",
|
||||
ArtifactDocumentType.Diff => "diff",
|
||||
_ => type.ToString().ToLowerInvariant()
|
||||
};
|
||||
|
||||
private static string MapLegacyFormatSegment(ArtifactDocumentFormat format) => format switch
|
||||
{
|
||||
ArtifactDocumentFormat.CycloneDxJson => "cyclonedx-json",
|
||||
ArtifactDocumentFormat.CycloneDxProtobuf => "cyclonedx-protobuf",
|
||||
ArtifactDocumentFormat.SpdxJson => "spdx-json",
|
||||
ArtifactDocumentFormat.BomIndex => "bom-index",
|
||||
ArtifactDocumentFormat.DsseJson => "dsse-json",
|
||||
ArtifactDocumentFormat.SurfaceManifestJson => "surface-manifest-json",
|
||||
ArtifactDocumentFormat.EntryTraceNdjson => "entrytrace-ndjson",
|
||||
ArtifactDocumentFormat.EntryTraceGraphJson => "entrytrace-graph-json",
|
||||
ArtifactDocumentFormat.ComponentFragmentJson => "component-fragment-json",
|
||||
_ => format.ToString().ToLowerInvariant()
|
||||
};
|
||||
|
||||
private static void RecordLatency(Stopwatch stopwatch)
|
||||
{
|
||||
stopwatch.Stop();
|
||||
|
||||
Reference in New Issue
Block a user