question

Sabuncu avatar image
0 Votes"
Sabuncu asked Sabuncu edited

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

I am following this tutorial here: https://docs.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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
1 Vote"
shivapatpi-MSFT answered Sabuncu edited

Hello @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
(OR)
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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@shivapatpi-MSFT , thank you for your answer. You're right, I missed the part about the ResourcesManagementClient() being needed for the delete operation.

If I may, I have a follow-up question: I would like to modify this sample so that it uses Managed Identities to do what it does currently. Can you guide me towards a sample that does this?

Again, many thanks for your attention and your time, much obliged.

0 Votes 0 ·