Files
Flypaper/src/Flypaper.Storage/FlypaperStorageExtensions.cs
T
TomandClaude Sonnet 5.5 4b946453fb
Build and deploy / build (push) Successful in 1m33s
Build and deploy / deploy (push) Successful in 20s
Answer first visits to / and favicon with an instant WordPress lure
Unknown IPs get a small WordPress-looking page or icon and are not held;
later requests are trapped as before. Switch: Flypaper__Drip__Lure.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 12:57:29 +01:00

62 lines
2.6 KiB
C#

using Flypaper.Core.Abstractions;
using Flypaper.Storage.Dashboard;
using Flypaper.Storage.Events;
using Flypaper.Storage.Explanations;
using Flypaper.Storage.Maintenance;
using Flypaper.Storage.Queries;
using Flypaper.Storage.Settings;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Flypaper.Storage;
public static class FlypaperStorageExtensions
{
public static IHostApplicationBuilder AddFlypaperStorage(this IHostApplicationBuilder builder)
{
var connectionString = builder.Configuration.GetConnectionString("Flypaper") ?? "Data Source=flypaper.db";
var source = new DbConfigurationSource(connectionString);
builder.Configuration.Add(source);
builder.Services.AddSingleton(source);
builder.Services.AddSingleton<RuntimeSettingsStore>();
builder.Services.AddSingleton<AdminCredentialStore>();
builder.Services.AddSingleton<McpTokenStore>();
builder.Services.Configure<RetentionOptions>(builder.Configuration.GetSection(RetentionOptions.SectionName));
builder.Services.AddFlypaperStorage(connectionString);
return builder;
}
public static IServiceCollection AddFlypaperStorage(this IServiceCollection services, string connectionString)
{
services.AddDbContextFactory<FlypaperDbContext>(options => options.UseSqlite(connectionString));
services.AddSingleton<ChannelTrapEventSink>();
services.AddSingleton<ITrapEventSink>(sp => sp.GetRequiredService<ChannelTrapEventSink>());
services.AddHostedService<TrapEventWriter>();
services.AddHostedService<OriginBackfill>();
services.AddSingleton<ExplanationRuleStore>();
services.AddSingleton<ExplanationQueries>();
services.AddSingleton<DashboardQueries>();
services.AddSingleton<CatchQueries>();
services.AddSingleton<IRepeatOffenderLookup, RepeatOffenderLookup>();
services.AddSingleton<IKnownIpLookup, KnownIpLookup>();
services.AddSingleton<TrapDataMaintenance>();
services.AddHostedService<RetentionCleanup>();
return services;
}
public static async Task MigrateFlypaperDatabaseAsync(this IServiceProvider services, CancellationToken ct = default)
{
var factory = services.GetRequiredService<IDbContextFactory<FlypaperDbContext>>();
await using (var db = await factory.CreateDbContextAsync(ct))
{
await db.Database.MigrateAsync(ct);
}
services.GetService<DbConfigurationSource>()?.TryReload();
}
}