work
This commit is contained in:
@@ -18,23 +18,10 @@ builder.Services.AddOptions();
|
||||
builder.Services.AddLogging();
|
||||
|
||||
// Register SBOM query services (InMemory seed; replace with Mongo-backed repository later).
|
||||
builder.Services.AddSingleton<IComponentLookupRepository>(sp =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = sp.GetRequiredService<IConfiguration>();
|
||||
var mongoConn = config.GetConnectionString("SbomServiceMongo") ?? "mongodb://localhost:27017";
|
||||
var mongoClient = new MongoDB.Driver.MongoClient(mongoConn);
|
||||
var databaseName = config.GetSection("SbomService")?["Database"] ?? "sbomservice";
|
||||
var database = mongoClient.GetDatabase(databaseName);
|
||||
return new MongoComponentLookupRepository(database);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback for test/offline environments when Mongo driver is unavailable.
|
||||
return new InMemoryComponentLookupRepository();
|
||||
}
|
||||
});
|
||||
builder.Services.AddSingleton<IComponentLookupRepository>(_ => new InMemoryComponentLookupRepository());
|
||||
builder.Services.AddSingleton<IClock, SystemClock>();
|
||||
builder.Services.AddSingleton<ISbomEventStore, InMemorySbomEventStore>();
|
||||
builder.Services.AddSingleton<ISbomEventPublisher>(sp => sp.GetRequiredService<ISbomEventStore>());
|
||||
builder.Services.AddSingleton<ISbomQueryService, InMemorySbomQueryService>();
|
||||
|
||||
builder.Services.AddSingleton<IProjectionRepository>(sp =>
|
||||
@@ -279,6 +266,39 @@ app.MapGet("/sboms/{snapshotId}/projection", async Task<IResult> (
|
||||
});
|
||||
});
|
||||
|
||||
app.MapGet("/internal/sbom/events", async Task<IResult> (
|
||||
[FromServices] ISbomEventStore store,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var events = await store.ListAsync(cancellationToken);
|
||||
return Results.Ok(events);
|
||||
});
|
||||
|
||||
app.MapPost("/internal/sbom/events/backfill", async Task<IResult> (
|
||||
[FromServices] IProjectionRepository repository,
|
||||
[FromServices] ISbomEventPublisher publisher,
|
||||
[FromServices] IClock clock,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var projections = await repository.ListAsync(cancellationToken);
|
||||
var published = 0;
|
||||
foreach (var projection in projections)
|
||||
{
|
||||
var evt = new SbomVersionCreatedEvent(
|
||||
projection.SnapshotId,
|
||||
projection.TenantId,
|
||||
projection.ProjectionHash,
|
||||
projection.SchemaVersion,
|
||||
clock.UtcNow);
|
||||
if (await publisher.PublishVersionCreatedAsync(evt, cancellationToken))
|
||||
{
|
||||
published++;
|
||||
}
|
||||
}
|
||||
|
||||
return Results.Ok(new { published });
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
public partial class Program;
|
||||
|
||||
Reference in New Issue
Block a user