stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using StellaOps.AuditPack.Models;
|
||||
|
||||
namespace StellaOps.AuditPack.Services;
|
||||
|
||||
public sealed partial class IsolatedReplayContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the replay context from a bundle read result.
|
||||
/// </summary>
|
||||
public async Task<ReplayContextInitResult> InitializeAsync(
|
||||
AuditBundleReadResult bundleResult,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(nameof(IsolatedReplayContext));
|
||||
}
|
||||
|
||||
if (!bundleResult.Success || bundleResult.ReplayInputs is null)
|
||||
{
|
||||
return ReplayContextInitResult.Failed("Bundle read result is invalid or has no replay inputs");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var inputs = bundleResult.ReplayInputs;
|
||||
if (inputs.Sbom is null)
|
||||
{
|
||||
return ReplayContextInitResult.Failed("SBOM is required for replay");
|
||||
}
|
||||
|
||||
Sbom = inputs.Sbom;
|
||||
SbomDigest = ComputeDigest(Sbom);
|
||||
|
||||
if (inputs.FeedsSnapshot is null)
|
||||
{
|
||||
return ReplayContextInitResult.Failed("Feeds snapshot is required for replay");
|
||||
}
|
||||
|
||||
FeedsSnapshot = inputs.FeedsSnapshot;
|
||||
FeedsDigest = ComputeDigest(FeedsSnapshot);
|
||||
|
||||
if (inputs.PolicyBundle is null)
|
||||
{
|
||||
return ReplayContextInitResult.Failed("Policy bundle is required for replay");
|
||||
}
|
||||
|
||||
PolicyBundle = inputs.PolicyBundle;
|
||||
PolicyDigest = ComputeDigest(PolicyBundle);
|
||||
|
||||
if (inputs.VexStatements is not null)
|
||||
{
|
||||
VexStatements = inputs.VexStatements;
|
||||
VexDigest = ComputeDigest(VexStatements);
|
||||
}
|
||||
|
||||
if (inputs.Verdict is not null)
|
||||
{
|
||||
OriginalVerdict = inputs.Verdict;
|
||||
}
|
||||
|
||||
if (bundleResult.Manifest?.TimeAnchor?.Timestamp is DateTimeOffset anchorTime)
|
||||
{
|
||||
EvaluationTime = anchorTime;
|
||||
}
|
||||
|
||||
await ExtractInputsAsync(cancellationToken).ConfigureAwait(false);
|
||||
IsInitialized = true;
|
||||
|
||||
return new ReplayContextInitResult
|
||||
{
|
||||
Success = true,
|
||||
SbomDigest = SbomDigest,
|
||||
FeedsDigest = FeedsDigest,
|
||||
PolicyDigest = PolicyDigest,
|
||||
VexDigest = VexDigest,
|
||||
EvaluationTime = EvaluationTime
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ReplayContextInitResult.Failed($"Failed to initialize replay context: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user