consolidation of some of the modules, localization fixes, product advisories work, qa work
This commit is contained in:
54
src/__Libraries/_archived/StellaOps.Resolver/Policy.cs
Normal file
54
src/__Libraries/_archived/StellaOps.Resolver/Policy.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Policy - Policy Model for Resolver
|
||||
* Sprint: SPRINT_9100_0001_0001 (Core Resolver Package)
|
||||
* Task: RESOLVER-9100-005
|
||||
*
|
||||
* Represents the policy used for verdict evaluation.
|
||||
* Policy digest is included in FinalDigest for reproducibility.
|
||||
*/
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace StellaOps.Resolver;
|
||||
|
||||
/// <summary>
|
||||
/// Policy configuration for deterministic resolution.
|
||||
/// </summary>
|
||||
/// <param name="Version">Policy version string.</param>
|
||||
/// <param name="Rules">Policy rules as JSON.</param>
|
||||
/// <param name="ConstantsDigest">SHA256 digest of policy constants.</param>
|
||||
public sealed record Policy(
|
||||
string Version,
|
||||
JsonElement Rules,
|
||||
string ConstantsDigest)
|
||||
{
|
||||
private string? _digest;
|
||||
|
||||
/// <summary>
|
||||
/// SHA256 digest of the policy (version + rules + constants).
|
||||
/// </summary>
|
||||
public string Digest => _digest ??= ComputeDigest();
|
||||
|
||||
private string ComputeDigest()
|
||||
{
|
||||
var input = $"{Version}:{Rules.GetRawText()}:{ConstantsDigest}";
|
||||
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(input));
|
||||
return Convert.ToHexString(hash).ToLowerInvariant();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a policy from version and rules JSON.
|
||||
/// </summary>
|
||||
public static Policy Create(string version, JsonElement rules, string constantsDigest = "")
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(version);
|
||||
return new Policy(version, rules, constantsDigest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty policy for testing.
|
||||
/// </summary>
|
||||
public static Policy Empty => new("1.0.0", JsonDocument.Parse("{}").RootElement, "");
|
||||
}
|
||||
Reference in New Issue
Block a user