save checkpoint: save features
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using StellaOps.Scanner.Core;
|
||||
|
||||
namespace StellaOps.Scanner.WebService.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Resolves scan metadata from stored scan manifests.
|
||||
/// </summary>
|
||||
public sealed class InMemoryScanMetadataRepository : IScanMetadataRepository
|
||||
{
|
||||
private readonly IScanManifestRepository _manifestRepository;
|
||||
|
||||
public InMemoryScanMetadataRepository(IScanManifestRepository manifestRepository)
|
||||
{
|
||||
_manifestRepository = manifestRepository ?? throw new ArgumentNullException(nameof(manifestRepository));
|
||||
}
|
||||
|
||||
public async Task<ScanMetadata?> GetScanMetadataAsync(string scanId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(scanId))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var manifest = await _manifestRepository
|
||||
.GetManifestAsync(scanId.Trim(), cancellationToken: cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (manifest is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ScanMetadata(
|
||||
BaseDigest: null,
|
||||
TargetDigest: NormalizeDigest(manifest.Manifest.ArtifactDigest),
|
||||
ScanTime: manifest.Manifest.CreatedAtUtc);
|
||||
}
|
||||
|
||||
private static string? NormalizeDigest(string? digest)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(digest))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var normalized = digest.Trim();
|
||||
if (!normalized.Contains(':', StringComparison.Ordinal))
|
||||
{
|
||||
normalized = $"sha256:{normalized}";
|
||||
}
|
||||
|
||||
return normalized.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user