131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
// <copyright file="ServiceCollectionExtensions.cs" company="StellaOps">
|
|
// Copyright (c) StellaOps. Licensed under the BUSL-1.1.
|
|
// </copyright>
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using StellaOps.Evidence.Pack.Resolvers;
|
|
using StellaOps.Evidence.Pack.Storage;
|
|
|
|
namespace StellaOps.Evidence.Pack;
|
|
|
|
/// <summary>
|
|
/// Extension methods for configuring Evidence Pack services.
|
|
/// Sprint: SPRINT_20260109_011_005 Task: EVPK-005
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds Evidence Pack services with default configuration.
|
|
/// </summary>
|
|
public static IServiceCollection AddEvidencePack(this IServiceCollection services)
|
|
{
|
|
return services.AddEvidencePack(_ => { });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds Evidence Pack services with custom configuration.
|
|
/// </summary>
|
|
public static IServiceCollection AddEvidencePack(
|
|
this IServiceCollection services,
|
|
Action<EvidencePackOptions> configure)
|
|
{
|
|
var options = new EvidencePackOptions();
|
|
configure(options);
|
|
|
|
// Core services
|
|
services.TryAddSingleton(TimeProvider.System);
|
|
services.TryAddScoped<IEvidencePackService, EvidencePackService>();
|
|
services.TryAddScoped<IEvidenceResolver, EvidenceResolver>();
|
|
|
|
// Default to in-memory store if not configured
|
|
services.TryAddSingleton<IEvidencePackStore, InMemoryEvidencePackStore>();
|
|
|
|
// Add null type resolver if none configured
|
|
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITypeResolver, NullTypeResolver>());
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a custom type resolver for evidence resolution.
|
|
/// </summary>
|
|
public static IServiceCollection AddEvidenceTypeResolver<TResolver>(
|
|
this IServiceCollection services)
|
|
where TResolver : class, ITypeResolver
|
|
{
|
|
services.AddSingleton<ITypeResolver, TResolver>();
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a custom type resolver factory for evidence resolution.
|
|
/// </summary>
|
|
public static IServiceCollection AddEvidenceTypeResolver(
|
|
this IServiceCollection services,
|
|
Func<IServiceProvider, ITypeResolver> factory)
|
|
{
|
|
services.AddSingleton(factory);
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a passthrough type resolver for testing.
|
|
/// </summary>
|
|
public static IServiceCollection AddPassthroughResolver(
|
|
this IServiceCollection services,
|
|
params string[] types)
|
|
{
|
|
services.AddSingleton<ITypeResolver>(sp =>
|
|
new PassthroughTypeResolver(types, sp.GetRequiredService<TimeProvider>()));
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Uses in-memory storage for Evidence Packs.
|
|
/// </summary>
|
|
public static IServiceCollection UseInMemoryEvidencePackStore(
|
|
this IServiceCollection services)
|
|
{
|
|
services.RemoveAll<IEvidencePackStore>();
|
|
services.AddSingleton<IEvidencePackStore, InMemoryEvidencePackStore>();
|
|
return services;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configuration options for Evidence Pack services.
|
|
/// </summary>
|
|
public sealed class EvidencePackOptions
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets whether to auto-create packs from grounding results.
|
|
/// </summary>
|
|
public bool AutoCreateEnabled { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the minimum grounding score for auto-creation.
|
|
/// </summary>
|
|
public double MinGroundingScore { get; set; } = 0.7;
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether to auto-sign created packs.
|
|
/// </summary>
|
|
public bool AutoSign { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the signing key identifier.
|
|
/// </summary>
|
|
public string? SigningKeyId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the retention period for unsigned packs in days.
|
|
/// </summary>
|
|
public int RetentionDays { get; set; } = 365;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the retention period for signed packs in days.
|
|
/// </summary>
|
|
public int SignedRetentionDays { get; set; } = 2555; // 7 years
|
|
}
|