Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ internal sealed class AzureKeyVaultCertificatesComponent : AbstractAzureKeyVault
internal override CertificateClient CreateComponentClient(Uri vaultUri, CertificateClientOptions options, TokenCredential cred)
=> new(vaultUri, cred, options);

protected override bool GetHealthCheckEnabled(AzureSecurityKeyVaultSettings settings)
=> false;

protected override IHealthCheck CreateHealthCheck(CertificateClient client, AzureSecurityKeyVaultSettings settings)
=> throw new NotImplementedException();
=> new AzureKeyVaultCertificatesHealthCheck(client);

protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<CertificateClient, CertificateClientOptions> clientBuilder, IConfiguration configuration)
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Azure.Security.KeyVault.Certificates;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Aspire.Azure.Security.KeyVault;

internal sealed class AzureKeyVaultCertificatesHealthCheck : IHealthCheck
{
private readonly CertificateClient _client;

public AzureKeyVaultCertificatesHealthCheck(CertificateClient client)
=> _client = client;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await foreach (var _ in _client.GetPropertiesOfCertificatesAsync(cancellationToken: cancellationToken).AsPages(pageSizeHint: 1).WithCancellation(cancellationToken).ConfigureAwait(false))
{
break;
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ namespace Microsoft.Extensions.Hosting;

internal sealed class AzureKeyVaultKeysComponent : AbstractAzureKeyVaultComponent<KeyClient, KeyClientOptions>
{
protected override bool GetHealthCheckEnabled(AzureSecurityKeyVaultSettings settings)
=> false;

protected override IHealthCheck CreateHealthCheck(KeyClient client, AzureSecurityKeyVaultSettings settings)
=> throw new NotImplementedException();
=> new AzureKeyVaultKeysHealthCheck(client);

internal override KeyClient CreateComponentClient(Uri vaultUri, KeyClientOptions options, TokenCredential cred)
=> new(vaultUri, cred, options);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Azure.Security.KeyVault.Keys;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Aspire.Azure.Security.KeyVault;

internal sealed class AzureKeyVaultKeysHealthCheck : IHealthCheck
{
private readonly KeyClient _client;

public AzureKeyVaultKeysHealthCheck(KeyClient client)
=> _client = client;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await foreach (var _ in _client.GetPropertiesOfKeysAsync(cancellationToken).AsPages(pageSizeHint: 1).WithCancellation(cancellationToken).ConfigureAwait(false))
{
break;
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ void ConfigureCredentials(AzureSecurityKeyVaultSettings settings)
}

protected override void SetHealthCheck(AzureSecurityKeyVaultSettings options, bool enabled)
// Disable Key Vault health check tests until https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2279 is fixed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if we fixed this issue in Xabaril/AspNetCore.Diagnostics.HealthChecks instead. And then used that library.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened PR to add the dedicated packages. Will update this PR to use them once merged and published to NuGet.

// => options.DisableHealthChecks = !enabled;
=> throw new NotImplementedException();
=> options.DisableHealthChecks = !enabled;

protected override void SetMetrics(AzureSecurityKeyVaultSettings options, bool enabled)
=> throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ void ConfigureCredentials(AzureSecurityKeyVaultSettings settings)
}

protected override void SetHealthCheck(AzureSecurityKeyVaultSettings options, bool enabled)
// Disable Key Vault health check tests until https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2279 is fixed
// => options.DisableHealthChecks = !enabled;
=> throw new NotImplementedException();
=> options.DisableHealthChecks = !enabled;

protected override void SetMetrics(AzureSecurityKeyVaultSettings options, bool enabled)
=> throw new NotImplementedException();
Expand Down
Loading