如何从资源 ID 获取 blob 属性
How to get blob properties from resource ID
我想知道给定 blob 的 ARM ID 或资源 ID,如何获取 blob 属性,例如 primaryEndpoints
示例资源 ID:
/subscriptions/abffff89-2c76-424a-af4c-34b2512a3cb4/resourceGroups/foo-bar-test-rg/providers/Microsoft.Storage/storageAccounts/foobar
有一个获取 blob 属性的 REST API,我想知道 C# azure-sdk 中是否有等效项?
https://docs.microsoft.com/en-us/rest/api/storagerp/storage-accounts/get-properties
您可以使用 Azure SDK
。您要安装的软件包是 Azure.ResourceManager.Storage
和 Azure.Identity
.
下面是根据资源 ID 获取有关存储帐户信息的代码:
using System;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Storage;
namespace SO69264616
{
class Program
{
static async Task Main(string[] args)
{
var resourceId = "/subscriptions/abffff89-2c76-424a-af4c-34b2512a3cb4/resourceGroups/foo-bar-test-rg/providers/Microsoft.Storage/storageAccounts/foobar";
var resourceElements = resourceId.Split("/", StringSplitOptions.RemoveEmptyEntries);
var subscriptionId = resourceElements[1];
var resourceGroupName = resourceElements[3];
var storageAccountName = resourceElements[resourceElements.Length - 1];
var credentials = new AzureCliCredential();
var armClient = new ArmClient(credentials);
Subscription subscription = armClient.GetSubscription($"/subscriptions/{subscriptionId}");
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(resourceGroupName);
StorageAccountContainer storageAccountContainer = resourceGroup.GetStorageAccounts();
StorageAccount storageAccount = await storageAccountContainer.GetAsync(storageAccountName);
Console.WriteLine(storageAccount.Data.PrimaryEndpoints.Blob);
Console.WriteLine("Hello World!");
}
}
}
我正在使用 AzureCliCredential
,因为出于某种原因 DefaultAzureCredential
对我不起作用。您应该先尝试 DefaultAzureCredential
。
我想知道给定 blob 的 ARM ID 或资源 ID,如何获取 blob 属性,例如 primaryEndpoints
示例资源 ID:
/subscriptions/abffff89-2c76-424a-af4c-34b2512a3cb4/resourceGroups/foo-bar-test-rg/providers/Microsoft.Storage/storageAccounts/foobar
有一个获取 blob 属性的 REST API,我想知道 C# azure-sdk 中是否有等效项?
https://docs.microsoft.com/en-us/rest/api/storagerp/storage-accounts/get-properties
您可以使用 Azure SDK
。您要安装的软件包是 Azure.ResourceManager.Storage
和 Azure.Identity
.
下面是根据资源 ID 获取有关存储帐户信息的代码:
using System;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Storage;
namespace SO69264616
{
class Program
{
static async Task Main(string[] args)
{
var resourceId = "/subscriptions/abffff89-2c76-424a-af4c-34b2512a3cb4/resourceGroups/foo-bar-test-rg/providers/Microsoft.Storage/storageAccounts/foobar";
var resourceElements = resourceId.Split("/", StringSplitOptions.RemoveEmptyEntries);
var subscriptionId = resourceElements[1];
var resourceGroupName = resourceElements[3];
var storageAccountName = resourceElements[resourceElements.Length - 1];
var credentials = new AzureCliCredential();
var armClient = new ArmClient(credentials);
Subscription subscription = armClient.GetSubscription($"/subscriptions/{subscriptionId}");
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(resourceGroupName);
StorageAccountContainer storageAccountContainer = resourceGroup.GetStorageAccounts();
StorageAccount storageAccount = await storageAccountContainer.GetAsync(storageAccountName);
Console.WriteLine(storageAccount.Data.PrimaryEndpoints.Blob);
Console.WriteLine("Hello World!");
}
}
}
我正在使用 AzureCliCredential
,因为出于某种原因 DefaultAzureCredential
对我不起作用。您应该先尝试 DefaultAzureCredential
。