简体   繁体   中英

Programmatically Get Storage Account Key

I am building a UWP application. I want to upload and download data to Azure Blob containers belonging to various storage accounts. I do not intend to store the connection strings as they keep rotating.

Is there a way to dynamically get the storage account key?

(I have the container name and Blob URL)

Once I get the account key, I can generate the connection string using:

DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<???>;EndpointSuffix=core.windows.net

Using Azure.Storage.Blob - V12

Way-1: There is one way to get the Storage account key is by using Azure CLI commands as below and I followed Microsoft-Document :

az storage account keys list -g xx -n yy

xx- Name of the resource group yy- Name of Storage account

在此处输入图像描述

Way 2: To get programmatically, Thanks to @Ivan Yang and I followed his SO-Thread :

 keys = storage_client.storage_accounts.list_keys(RESOURCE_GROUP_NAME,STORAGE_ACCOUNT_NAME)

So the Storage Account key is the value of keys.keys[0].value

Way 3: You can also get storage account key by using api and call the below api in c# to get the Key and I followed Microsoft-Document as below: POST Req:

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys?api-version=2021-09-01

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM