using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using StellaOps.AirGap.Policy; using StellaOps.Notifier.Worker.Channels; using StellaOps.Notify.Engine; using StellaOps.Notify.Queue; using StellaOps.Notify.Storage.Postgres; using StellaOps.Notifier.Worker.Storage; using StellaOps.Notifier.Worker.Dispatch; using StellaOps.Notifier.Worker.Options; using StellaOps.Notifier.Worker.Processing; using StellaOps.Notifier.Worker.Templates; var builder = Host.CreateApplicationBuilder(args); builder.Configuration .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(prefix: "NOTIFIER_"); builder.Logging.ClearProviders(); builder.Logging.AddSimpleConsole(options => { options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ "; options.UseUtcTimestamp = true; }); builder.Services.Configure(builder.Configuration.GetSection("notifier:worker")); builder.Services.AddSingleton(TimeProvider.System); var postgresSection = builder.Configuration.GetSection("notifier:storage:postgres"); builder.Services.AddNotifyPostgresStorage(builder.Configuration, postgresSection.Path); builder.Services.AddAirGapEgressPolicy(builder.Configuration); builder.Services.AddNotifyEventQueue(builder.Configuration, "notifier:queue"); builder.Services.AddHealthChecks().AddNotifyQueueHealthCheck(); // In-memory storage replacements (document store removed) builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); // Template service (versioning, localization, redaction) builder.Services.AddTemplateServices(options => { var provenanceUrl = builder.Configuration["notifier:provenance:baseUrl"]; if (!string.IsNullOrWhiteSpace(provenanceUrl)) { options.ProvenanceBaseUrl = provenanceUrl; } }); // Dispatch/rendering services builder.Services.AddHttpClient(client => { client.Timeout = TimeSpan.FromSeconds(30); client.DefaultRequestHeaders.Add("User-Agent", "StellaOps-Notifier/1.0"); }); builder.Services.AddScoped(); builder.Services.AddHostedService(); await builder.Build().RunAsync().ConfigureAwait(false);