Why is it that both a StorageManagementClient instance and storage account name are required?

A.M. Sabuncu 31 Reputation points

I am following this tutorial here: https://learn.microsoft.com/en-us/samples/dotnet/samples/azure-identity-resource-management-storage/

The associated code is here: https://github.com/dotnet/samples/blob/main/azure/sdk-identity-resources-storage/Program.cs

My question involves the following line of code:

string connectionString = await GetStorageConnectionStringAsync(storageManagementClient, resourceGroupName, storageAccountName);  

Why is it that both a StorageManagementClient instance and storage account name are required?

For resource group name, only the group name as a string is sufficient; no instance of ResourcesManagementClient() is necessary.

But in case of a StorageManagementClient(), you need its instance as well.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,909 questions
0 comments No comments
{count} votes

Accepted answer
  1. shiva patpi 13,166 Reputation points Microsoft Employee

    Hello @A.M. Sabuncu ,
    Thanks for your query !
    Basically GetStorageConnectionStringAsync has to form the connection string which needs "StorageAccount" and "StorageKeys".
    As reference to storage account was already established through StorageManagementClient in the main function which is local , hence that parameter is needed along with StorageAccountName in order to be accessible by other functions .

    Also if you observe , when the resource group is being cleaned up at the end , it is expecting both the ResourcesManagementClient and the ResourceGroupName.

    Of course , You can modify GetStorageConnectionStringAsync function in different ways:

    1) Declare that StorageManagementClient variable globally and access that with out passing the parameter to any function
    2) Modify the function GetStorageConnectionStringAsync like below if you don't want to pass the storage account name:

    For Example:
    StorageAccountsOperations saOper = storage.StorageAccounts; //Create an instance of Storage Operations from StorageManagementClient
    Pageable<StorageAccount> psa = saOper.List(); //Get all the Storage Accounts under subscriptions
    //get the keys etc

    Hope that helps . Let us know if you have additional questions !

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful