Reputation: 1592
I am wondering given ARM ID or resource ID of blob, how to get blob properties such as primaryEndpoints
Example resource ID:
/subscriptions/abffff89-2c76-424a-af4c-34b2512a3cb4/resourceGroups/foo-bar-test-rg/providers/Microsoft.Storage/storageAccounts/foobar
There is a get blob properties REST API, I am wondering is there an equivalent in C# azure-sdk?
https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/get-properties
Upvotes: 1
Views: 748
Reputation: 136386
You can use Azure SDK
for that. The packages you would want to install are Azure.ResourceManager.Storage
and Azure.Identity
.
Here's the code to get the information about a storage account based on the resource 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!");
}
}
}
I am using AzureCliCredential
because for some reason DefaultAzureCredential
did not work for me. You should try with DefaultAzureCredential
first.
Upvotes: 1