Add tests and implement timeline ingestion options with NATS and Redis subscribers
- Introduced `BinaryReachabilityLifterTests` to validate binary lifting functionality. - Created `PackRunWorkerOptions` for configuring worker paths and execution persistence. - Added `TimelineIngestionOptions` for configuring NATS and Redis ingestion transports. - Implemented `NatsTimelineEventSubscriber` for subscribing to NATS events. - Developed `RedisTimelineEventSubscriber` for reading from Redis Streams. - Added `TimelineEnvelopeParser` to normalize incoming event envelopes. - Created unit tests for `TimelineEnvelopeParser` to ensure correct field mapping. - Implemented `TimelineAuthorizationAuditSink` for logging authorization outcomes.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json;
|
||||
using StellaOps.SbomService.Models;
|
||||
|
||||
namespace StellaOps.SbomService.Repositories;
|
||||
|
||||
public sealed class FileComponentLookupRepository : IComponentLookupRepository
|
||||
{
|
||||
private readonly IReadOnlyList<ComponentLookupRecord> _items;
|
||||
|
||||
public FileComponentLookupRepository(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
_items = Array.Empty<ComponentLookupRecord>();
|
||||
return;
|
||||
}
|
||||
|
||||
using var stream = File.OpenRead(path);
|
||||
var items = JsonSerializer.Deserialize<List<ComponentLookupRecord>>(stream, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
_items = items ?? Array.Empty<ComponentLookupRecord>();
|
||||
}
|
||||
|
||||
public Task<(IReadOnlyList<ComponentLookupRecord> Items, int Total)> QueryAsync(ComponentLookupQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
var filtered = _items
|
||||
.Where(c => c.Purl.Equals(query.Purl, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(c => query.Artifact is null || c.Artifact.Equals(query.Artifact, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(c => c.Artifact)
|
||||
.ThenBy(c => c.Purl)
|
||||
.ToList();
|
||||
|
||||
var page = filtered
|
||||
.Skip(query.Offset)
|
||||
.Take(query.Limit)
|
||||
.ToList();
|
||||
|
||||
return Task.FromResult<(IReadOnlyList<ComponentLookupRecord> Items, int Total)>((page, filtered.Count));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user