是否有一种简单的方法来检查具有多个密钥的 Azure Blob 存储的运行状况?

Is there an easy way to health-check an Azure blob storage with multiple keys?

我正在使用 ASP.NET Core(C#、.NET 6)构建 Azure Web 服务。我有一个 Azure 存储帐户。存储帐户有两 (2) 个访问密钥。这个想法是,如果第一个密钥过期或需要更改,应用程序可以无缝切换到第二个密钥,同时运营商更新第一个密钥。

我的应用程序有健康检查,我想包括存储帐户的健康检查。我从这篇文章中得到灵感:https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/monitor-app-health#healthchecks-implementation-in-eshoponcontainers

我写了这样的代码,使用 NuGet 包 AspNetCore.HealthChecks.AzureStorage:

services.AddHealthChecks()
    .AddAzureBlobStorage(
        $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={key1};EndpointSuffix=core.windows.net",
        name: "catalog-storage-check",
        tags: new string[] { "catalogstorage" });

问题是如果密钥 1 过期或被撤销,此健康检查将失败。那不是我想要的。我希望只要 至少 2 个键中的 1 个 有效,健康检查就会成功,如果 两个键都失败 .

有没有简单的方法可以做到这一点,还是我必须自己编写代码?

我看了AspNetCore.HealthChecks.AzureStorage的实现。

https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/2f582f42a3e5c7dc73bfdb114d6031d711552af6/test/HealthChecks.AzureStorage.Tests/DependencyInjection/AzureBlobStorageRegistrationTests.cs

其实很简单。它只是检查是否存在 blob 容器。

所以我只是用同样的想法做了我自己的实现,但是如果第一个键不起作用就重试。 (如果第一个键失败,我已经有了重试操作的通用方法。)