wip - advisories and ui extensions
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using StellaOps.Scanner.Sources.Configuration;
|
||||
using StellaOps.Scanner.Sources.ConnectionTesters;
|
||||
using StellaOps.Scanner.Sources.Handlers;
|
||||
using StellaOps.Scanner.Sources.Handlers.Cli;
|
||||
using StellaOps.Scanner.Sources.Handlers.Docker;
|
||||
using StellaOps.Scanner.Sources.Handlers.Git;
|
||||
using StellaOps.Scanner.Sources.Handlers.Zastava;
|
||||
using StellaOps.Scanner.Sources.Persistence;
|
||||
using StellaOps.Scanner.Sources.Scheduling;
|
||||
using StellaOps.Scanner.Sources.Services;
|
||||
using StellaOps.Scanner.Sources.Triggers;
|
||||
|
||||
namespace StellaOps.Scanner.Sources.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for registering Scanner.Sources services.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds SBOM source management services to the service collection.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddSbomSources(
|
||||
this IServiceCollection services,
|
||||
Action<SbomSourcesOptions>? configure = null)
|
||||
{
|
||||
var options = new SbomSourcesOptions();
|
||||
configure?.Invoke(options);
|
||||
|
||||
// Register options
|
||||
services.AddSingleton(options);
|
||||
|
||||
// Register core services
|
||||
services.AddScoped<ISbomSourceService, SbomSourceService>();
|
||||
services.AddScoped<ISourceConfigValidator, SourceConfigValidator>();
|
||||
services.AddScoped<ISourceConnectionTester, SourceConnectionTester>();
|
||||
|
||||
// Register repositories
|
||||
services.AddScoped<ISbomSourceRepository, SbomSourceRepository>();
|
||||
services.AddScoped<ISbomSourceRunRepository, SbomSourceRunRepository>();
|
||||
|
||||
// Register connection testers
|
||||
services.AddScoped<ISourceTypeConnectionTester, ZastavaConnectionTester>();
|
||||
services.AddScoped<ISourceTypeConnectionTester, DockerConnectionTester>();
|
||||
services.AddScoped<ISourceTypeConnectionTester, GitConnectionTester>();
|
||||
services.AddScoped<ISourceTypeConnectionTester, CliConnectionTester>();
|
||||
|
||||
// Register source type handlers
|
||||
services.AddScoped<ISourceTypeHandler, ZastavaSourceHandler>();
|
||||
services.AddScoped<ISourceTypeHandler, DockerSourceHandler>();
|
||||
services.AddScoped<ISourceTypeHandler, GitSourceHandler>();
|
||||
services.AddScoped<ISourceTypeHandler, CliSourceHandler>();
|
||||
|
||||
// Register trigger dispatcher
|
||||
services.AddScoped<ISourceTriggerDispatcher, SourceTriggerDispatcher>();
|
||||
|
||||
// Register image discovery service
|
||||
services.AddSingleton<IImageDiscoveryService, ImageDiscoveryService>();
|
||||
|
||||
// Register HTTP client for connection testing
|
||||
services.AddHttpClient("SourceConnectionTest", client =>
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "StellaOps-SourceConnectionTester/1.0");
|
||||
client.Timeout = TimeSpan.FromSeconds(30);
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the source scheduler background service.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddSbomSourceScheduler(
|
||||
this IServiceCollection services,
|
||||
Action<SourceSchedulerOptions>? configure = null)
|
||||
{
|
||||
services.Configure<SourceSchedulerOptions>(opt =>
|
||||
{
|
||||
configure?.Invoke(opt);
|
||||
});
|
||||
|
||||
services.TryAddSingleton(TimeProvider.System);
|
||||
services.AddHostedService<SourceSchedulerHostedService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a custom credential resolver for SBOM sources.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddSbomSourceCredentialResolver<TResolver>(
|
||||
this IServiceCollection services)
|
||||
where TResolver : class, ICredentialResolver
|
||||
{
|
||||
services.AddScoped<ICredentialResolver, TResolver>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Options for SBOM source management.
|
||||
/// </summary>
|
||||
public sealed class SbomSourcesOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Default timeout for connection tests in seconds.
|
||||
/// </summary>
|
||||
public int ConnectionTestTimeoutSeconds { get; set; } = 30;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of runs to retain per source.
|
||||
/// </summary>
|
||||
public int MaxRunsPerSource { get; set; } = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to enable connection test caching.
|
||||
/// </summary>
|
||||
public bool EnableConnectionTestCaching { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Connection test cache duration in minutes.
|
||||
/// </summary>
|
||||
public int ConnectionTestCacheMinutes { get; set; } = 5;
|
||||
}
|
||||
Reference in New Issue
Block a user