Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StorageAccountHelper.cs
internal class StorageAccountHelper
{
internal async Task<StorageKeys> GetStorageKeysAsync()
{
var token = await new TokenHelper().GetManagementApiAccessTokenAsync();
return await GetStorageKeysAsync(token);
}
internal async Task<StorageKeys> GetStorageKeysAsync(string token)
{
var uri = new Uri($"{Constants.AzureManagementAPI}subscriptions/{Constants.SubscriptionID}/resourceGroups/{Constants.ResourceGroupName}/providers/Microsoft.Storage/storageAccounts/{Constants.StorageAccountName}/listKeys?api-version=2016-01-01");
var content = new StringContent(string.Empty, Encoding.UTF8, "text/html");
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization
= new AuthenticationHeaderValue("Bearer", token);
using (var response = await httpClient.PostAsync(uri, content))
{
var responseText = await response.Content.ReadAsStringAsync();
var keys = JsonConvert.DeserializeObject<StorageKeys>(responseText);
return keys;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.