diff --git a/README.md b/README.md index 6641300..6afef36 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ An example of one topic with one subscriber is shown below. - `false` (the default) subscription validation will be attempted each time the simulator starts. - `true` to disable subscription validation. +### App Settings + +- `dangerousAcceptAnyServerCertificateValidator`: Set to `true` to accept any server certificate. This is useful when testing with self signed certificates. + #### Subscription Validation When a subscription is added to Azure Event Grid it first sends a validation event to the subscription endpoint. The validation event contains a `validationCode` which the subscription endpoint must echo back. If this does not occur then Azure Event Grid will not enable the subscription. diff --git a/src/AzureEventGridSimulator/Program.cs b/src/AzureEventGridSimulator/Program.cs index b67a8a4..0536162 100644 --- a/src/AzureEventGridSimulator/Program.cs +++ b/src/AzureEventGridSimulator/Program.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading; @@ -175,7 +176,16 @@ private static WebApplicationBuilder ConfigureWebHost(string[] args, IConfigurat builder.Services.AddSimulatorSettings(configuration); builder.Services.AddMediatR(o=> o.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); - builder.Services.AddHttpClient(); + + var httpClientBuilder = builder.Services.AddHttpClient(nameof(AzureEventGridSimulator)); + if (configuration.GetValue("dangerousAcceptAnyServerCertificateValidator")) + { + Log.Warning("DangerousAcceptAnyServerCertificateValidator is enabled. This should only be used for testing purposes"); + httpClientBuilder.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + { + ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator + }); + } builder.Services.AddScoped(); builder.Services.AddSingleton(); @@ -200,7 +210,7 @@ private static WebApplicationBuilder ConfigureWebHost(string[] args, IConfigurat .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.WithProperty("Environment", context.Configuration.EnvironmentName()) .Enrich.WithProperty("Application", nameof(AzureEventGridSimulator)) - .Enrich.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version) + .Enrich.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown") // The sensible defaults .MinimumLevel.Is(LogEventLevel.Information) .MinimumLevel.Override("Microsoft", LogEventLevel.Error)