Add channel test providers for Email, Slack, Teams, and Webhook
- Implemented EmailChannelTestProvider to generate email preview payloads. - Implemented SlackChannelTestProvider to create Slack message previews. - Implemented TeamsChannelTestProvider for generating Teams Adaptive Card previews. - Implemented WebhookChannelTestProvider to create webhook payloads. - Added INotifyChannelTestProvider interface for channel-specific preview generation. - Created ChannelTestPreviewContracts for request and response models. - Developed NotifyChannelTestService to handle test send requests and generate previews. - Added rate limit policies for test sends and delivery history. - Implemented unit tests for service registration and binding. - Updated project files to include necessary dependencies and configurations.
This commit is contained in:
		@@ -1,54 +1,57 @@
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection.Extensions;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Microsoft.Extensions.Options;
 | 
			
		||||
using MongoDB.Driver;
 | 
			
		||||
using StellaOps.Concelier.Core.Jobs;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Advisories;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Aliases;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.ChangeHistory;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Documents;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Dtos;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Exporting;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.JpFlags;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.MergeEvents;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.PsirtFlags;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Migrations;
 | 
			
		||||
 | 
			
		||||
namespace StellaOps.Concelier.Storage.Mongo;
 | 
			
		||||
 | 
			
		||||
public static class ServiceCollectionExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static IServiceCollection AddMongoStorage(this IServiceCollection services, Action<MongoStorageOptions> configureOptions)
 | 
			
		||||
    {
 | 
			
		||||
        ArgumentNullException.ThrowIfNull(services);
 | 
			
		||||
        ArgumentNullException.ThrowIfNull(configureOptions);
 | 
			
		||||
 | 
			
		||||
        services.AddOptions<MongoStorageOptions>()
 | 
			
		||||
            .Configure(configureOptions)
 | 
			
		||||
            .PostConfigure(static options => options.EnsureValid());
 | 
			
		||||
 | 
			
		||||
        services.TryAddSingleton(TimeProvider.System);
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoClient>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var options = sp.GetRequiredService<IOptions<MongoStorageOptions>>().Value;
 | 
			
		||||
            return new MongoClient(options.ConnectionString);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection.Extensions;
 | 
			
		||||
using Microsoft.Extensions.Options;
 | 
			
		||||
using MongoDB.Driver;
 | 
			
		||||
using StellaOps.Concelier.Core.Jobs;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Advisories;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Aliases;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.ChangeHistory;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Documents;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Dtos;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Exporting;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.JpFlags;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.MergeEvents;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Conflicts;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.PsirtFlags;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Statements;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Events;
 | 
			
		||||
using StellaOps.Concelier.Core.Events;
 | 
			
		||||
using StellaOps.Concelier.Storage.Mongo.Migrations;
 | 
			
		||||
 | 
			
		||||
namespace StellaOps.Concelier.Storage.Mongo;
 | 
			
		||||
 | 
			
		||||
public static class ServiceCollectionExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static IServiceCollection AddMongoStorage(this IServiceCollection services, Action<MongoStorageOptions> configureOptions)
 | 
			
		||||
    {
 | 
			
		||||
        ArgumentNullException.ThrowIfNull(services);
 | 
			
		||||
        ArgumentNullException.ThrowIfNull(configureOptions);
 | 
			
		||||
 | 
			
		||||
        services.AddOptions<MongoStorageOptions>()
 | 
			
		||||
            .Configure(configureOptions)
 | 
			
		||||
            .PostConfigure(static options => options.EnsureValid());
 | 
			
		||||
 | 
			
		||||
        services.TryAddSingleton(TimeProvider.System);
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoClient>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var options = sp.GetRequiredService<IOptions<MongoStorageOptions>>().Value;
 | 
			
		||||
            return new MongoClient(options.ConnectionString);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var options = sp.GetRequiredService<IOptions<MongoStorageOptions>>().Value;
 | 
			
		||||
            var client = sp.GetRequiredService<IMongoClient>();
 | 
			
		||||
            var settings = new MongoDatabaseSettings
 | 
			
		||||
            {
 | 
			
		||||
                ReadConcern = ReadConcern.Majority,
 | 
			
		||||
                WriteConcern = WriteConcern.WMajority,
 | 
			
		||||
                ReadPreference = ReadPreference.PrimaryPreferred,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var database = client.GetDatabase(options.GetDatabaseName(), settings);
 | 
			
		||||
            var writeConcern = database.Settings.WriteConcern.With(wTimeout: options.CommandTimeout);
 | 
			
		||||
            {
 | 
			
		||||
                ReadConcern = ReadConcern.Majority,
 | 
			
		||||
                WriteConcern = WriteConcern.WMajority,
 | 
			
		||||
                ReadPreference = ReadPreference.PrimaryPreferred,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            var database = client.GetDatabase(options.GetDatabaseName(), settings);
 | 
			
		||||
            var writeConcern = database.Settings.WriteConcern.With(wTimeout: options.CommandTimeout);
 | 
			
		||||
            return database.WithWriteConcern(writeConcern);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
@@ -56,36 +59,41 @@ public static class ServiceCollectionExtensions
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<MongoBootstrapper>();
 | 
			
		||||
        services.AddSingleton<IJobStore, MongoJobStore>();
 | 
			
		||||
        services.AddSingleton<ILeaseStore, MongoLeaseStore>();
 | 
			
		||||
        services.AddSingleton<ISourceStateRepository, MongoSourceStateRepository>();
 | 
			
		||||
        services.AddSingleton<IDocumentStore, DocumentStore>();
 | 
			
		||||
        services.AddSingleton<IDtoStore, DtoStore>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryStore, AdvisoryStore>();
 | 
			
		||||
        services.AddSingleton<IAliasStore, AliasStore>();
 | 
			
		||||
        services.AddSingleton<IChangeHistoryStore, MongoChangeHistoryStore>();
 | 
			
		||||
        services.AddSingleton<IJpFlagStore, JpFlagStore>();
 | 
			
		||||
        services.AddSingleton<IPsirtFlagStore, PsirtFlagStore>();
 | 
			
		||||
        services.AddSingleton<IMergeEventStore, MergeEventStore>();
 | 
			
		||||
        services.AddSingleton<IExportStateStore, ExportStateStore>();
 | 
			
		||||
        services.TryAddSingleton<ExportStateManager>();
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoCollection<JobRunDocument>>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var database = sp.GetRequiredService<IMongoDatabase>();
 | 
			
		||||
            return database.GetCollection<JobRunDocument>(MongoStorageDefaults.Collections.Jobs);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoCollection<JobLeaseDocument>>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var database = sp.GetRequiredService<IMongoDatabase>();
 | 
			
		||||
            return database.GetCollection<JobLeaseDocument>(MongoStorageDefaults.Collections.Locks);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        services.AddHostedService<RawDocumentRetentionService>();
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<ILeaseStore, MongoLeaseStore>();
 | 
			
		||||
        services.AddSingleton<ISourceStateRepository, MongoSourceStateRepository>();
 | 
			
		||||
        services.AddSingleton<IDocumentStore, DocumentStore>();
 | 
			
		||||
        services.AddSingleton<IDtoStore, DtoStore>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryStore, AdvisoryStore>();
 | 
			
		||||
        services.AddSingleton<IAliasStore, AliasStore>();
 | 
			
		||||
        services.AddSingleton<IChangeHistoryStore, MongoChangeHistoryStore>();
 | 
			
		||||
        services.AddSingleton<IJpFlagStore, JpFlagStore>();
 | 
			
		||||
        services.AddSingleton<IPsirtFlagStore, PsirtFlagStore>();
 | 
			
		||||
        services.AddSingleton<IMergeEventStore, MergeEventStore>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryStatementStore, AdvisoryStatementStore>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryConflictStore, AdvisoryConflictStore>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryEventRepository, MongoAdvisoryEventRepository>();
 | 
			
		||||
        services.AddSingleton<IAdvisoryEventLog, AdvisoryEventLog>();
 | 
			
		||||
        services.AddSingleton<IExportStateStore, ExportStateStore>();
 | 
			
		||||
        services.TryAddSingleton<ExportStateManager>();
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoCollection<JobRunDocument>>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var database = sp.GetRequiredService<IMongoDatabase>();
 | 
			
		||||
            return database.GetCollection<JobRunDocument>(MongoStorageDefaults.Collections.Jobs);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<IMongoCollection<JobLeaseDocument>>(static sp =>
 | 
			
		||||
        {
 | 
			
		||||
            var database = sp.GetRequiredService<IMongoDatabase>();
 | 
			
		||||
            return database.GetCollection<JobLeaseDocument>(MongoStorageDefaults.Collections.Locks);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        services.AddHostedService<RawDocumentRetentionService>();
 | 
			
		||||
 | 
			
		||||
        services.AddSingleton<MongoMigrationRunner>();
 | 
			
		||||
        services.AddSingleton<IMongoMigration, EnsureDocumentExpiryIndexesMigration>();
 | 
			
		||||
        services.AddSingleton<IMongoMigration, EnsureGridFsExpiryIndexesMigration>();
 | 
			
		||||
        services.AddSingleton<IMongoMigration, EnsureAdvisoryEventCollectionsMigration>();
 | 
			
		||||
        services.AddSingleton<IMongoMigration, SemVerStyleBackfillMigration>();
 | 
			
		||||
 | 
			
		||||
        return services;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user