refactor(vulnexplorer): inject TimeProvider and IGuidProvider for determinism - DET-016
VexDecisionStore: Added TimeProvider and IGuidProvider injection for deterministic ID generation and timestamps in Create/Update methods. Added StellaOps.Determinism.Abstractions project reference.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using StellaOps.Determinism;
|
||||||
using StellaOps.VulnExplorer.Api.Models;
|
using StellaOps.VulnExplorer.Api.Models;
|
||||||
|
|
||||||
namespace StellaOps.VulnExplorer.Api.Data;
|
namespace StellaOps.VulnExplorer.Api.Data;
|
||||||
@@ -10,11 +11,19 @@ namespace StellaOps.VulnExplorer.Api.Data;
|
|||||||
public sealed class VexDecisionStore
|
public sealed class VexDecisionStore
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<Guid, VexDecisionDto> _decisions = new();
|
private readonly ConcurrentDictionary<Guid, VexDecisionDto> _decisions = new();
|
||||||
|
private readonly TimeProvider _timeProvider;
|
||||||
|
private readonly IGuidProvider _guidProvider;
|
||||||
|
|
||||||
|
public VexDecisionStore(TimeProvider? timeProvider = null, IGuidProvider? guidProvider = null)
|
||||||
|
{
|
||||||
|
_timeProvider = timeProvider ?? TimeProvider.System;
|
||||||
|
_guidProvider = guidProvider ?? SystemGuidProvider.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
public VexDecisionDto Create(CreateVexDecisionRequest request, string userId, string userDisplayName)
|
public VexDecisionDto Create(CreateVexDecisionRequest request, string userId, string userDisplayName)
|
||||||
{
|
{
|
||||||
var id = Guid.NewGuid();
|
var id = _guidProvider.NewGuid();
|
||||||
var now = DateTimeOffset.UtcNow;
|
var now = _timeProvider.GetUtcNow();
|
||||||
|
|
||||||
var decision = new VexDecisionDto(
|
var decision = new VexDecisionDto(
|
||||||
Id: id,
|
Id: id,
|
||||||
@@ -52,7 +61,7 @@ public sealed class VexDecisionStore
|
|||||||
Scope = request.Scope ?? existing.Scope,
|
Scope = request.Scope ?? existing.Scope,
|
||||||
ValidFor = request.ValidFor ?? existing.ValidFor,
|
ValidFor = request.ValidFor ?? existing.ValidFor,
|
||||||
SupersedesDecisionId = request.SupersedesDecisionId ?? existing.SupersedesDecisionId,
|
SupersedesDecisionId = request.SupersedesDecisionId ?? existing.SupersedesDecisionId,
|
||||||
UpdatedAt = DateTimeOffset.UtcNow
|
UpdatedAt = _timeProvider.GetUtcNow()
|
||||||
};
|
};
|
||||||
|
|
||||||
_decisions[id] = updated;
|
_decisions[id] = updated;
|
||||||
|
|||||||
@@ -12,4 +12,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../../__Libraries/StellaOps.Determinism.Abstractions/StellaOps.Determinism.Abstractions.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user