| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| | | 3 | | |
| | | 4 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 5 | | |
| | | 6 | | /// <summary>Opt-in health bridge. It reports the latest redacted test observation and never performs provider traffic.< |
| | 1 | 7 | | public sealed class ExternalAuthenticationHealthCheck( |
| | 1 | 8 | | IIdentityProviderConnectionRegistry registry, |
| | 1 | 9 | | IConnectionObservationStore observations) : IHealthCheck |
| | | 10 | | { |
| | | 11 | | public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToke |
| | | 12 | | { |
| | 1 | 13 | | var registrySnapshot = await registry.GetAsync(string.Empty, cancellationToken); |
| | 2 | 14 | | var enabled = registrySnapshot.Connections.Where(x => x.Connection.IsEnabled && x.Connection.ArchivedAt is null |
| | 1 | 15 | | if (enabled.Length == 0) |
| | 0 | 16 | | return HealthCheckResult.Healthy("No enabled external identity provider connections."); |
| | | 17 | | |
| | 2 | 18 | | var latest = await Task.WhenAll(enabled.Select(x => observations.FindLatestAsync(x.Connection.Id, cancellationTo |
| | 2 | 19 | | if (latest.Any(x => x?.Status == Models.ConnectionObservationStatus.Failed)) |
| | 1 | 20 | | return HealthCheckResult.Degraded("One or more explicitly tested connections last failed."); |
| | 0 | 21 | | return HealthCheckResult.Healthy("Latest explicit connection tests contain no failures."); |
| | 1 | 22 | | } |
| | | 23 | | } |