Skip to content

Commit

Permalink
Updated DiagnosticEndpoints and added validation to service bus options
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Anderson committed Dec 13, 2024
1 parent 0782d4b commit 75bb4fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
22 changes: 8 additions & 14 deletions Btms.Backend/Endpoints/DiagnosticEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System.Net;
using Btms.Backend.Asb;
using Btms.Backend.Config;
Expand All @@ -23,31 +22,26 @@ public static void UseDiagnosticEndpoints(this IEndpointRouteBuilder app, IOptio
app.MapGet(BaseRoute + "/asb", GetAzureServiceBusDiagnosticAsync).AllowAnonymous();
}
}

private static async Task<IResult> GetBlobDiagnosticAsync(IBlobService service)
{
var result = await service.CheckBlobAsync(5, 1);
if (result.Success)
{
return Results.Ok(result);
return Results.Ok(result);
}
return Results.Conflict(result);
}

private static async Task<IResult> GetAzureServiceBusDiagnosticAsync(IOptions<ServiceBusOptions> serviceBusOptions, IWebProxy proxy)
private static async Task<IResult> GetAzureServiceBusDiagnosticAsync(HealthCheckService healthCheckService)
{
var options = new AzureServiceBusSubscriptionHealthCheckHealthCheckOptions(serviceBusOptions.Value.Topic, serviceBusOptions.Value.Subscription)
{
ConnectionString = serviceBusOptions.Value.ConnectionString
};
var healthReport = await healthCheckService.CheckHealthAsync(x => x.Name == "azuresubscription");

var healthCheck = new AzureServiceBusSubscriptionHealthCheck(options, new BtmsServiceBusClientProvider(proxy));
var result = await healthCheck.CheckHealthAsync(new HealthCheckContext());

if (result.Status == HealthStatus.Healthy)
if (healthReport.Status == HealthStatus.Healthy)
{
return Results.Ok(result);
return Results.Ok(healthReport);
}
return Results.Conflict(result);
return Results.Conflict(healthReport);

}
}
3 changes: 2 additions & 1 deletion Btms.Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static void ConfigureWebApplication(WebApplicationBuilder builder)

builder.Services
.AddOptions<ServiceBusOptions>()
.Bind(builder.Configuration.GetSection(ServiceBusOptions.SectionName));
.Bind(builder.Configuration.GetSection(ServiceBusOptions.SectionName))
.ValidateDataAnnotations();

builder.Services.BtmsAddOptions<ApiOptions, ApiOptions.Validator>(builder.Configuration, ApiOptions.SectionName)
.PostConfigure(options =>
Expand Down

0 comments on commit 75bb4fd

Please sign in to comment.