Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use V2 Storage accounts for RM based Diagnostics Extenstion #1112

Merged
merged 2 commits into from
Oct 20, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.WindowsAzure.Commands.Common.Storage;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Management.Storage;
using Microsoft.Azure.Commands.Management.Storage;
using Microsoft.Azure.Management.Storage;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Compute
Expand All @@ -37,7 +38,7 @@ public class SetAzureVMDiagnosticsExtensionCommand : VirtualMachineExtensionBase
private const string VirtualMachineExtension = "Microsoft.Compute/virtualMachines/extensions";
private const string IaaSDiagnosticsExtension = "IaaSDiagnostics";
private const string ExtensionPublisher = "Microsoft.Azure.Diagnostics";
private StorageManagementClient storageClient;
private IStorageManagementClient storageClient;

[Parameter(
Mandatory = true,
Expand Down Expand Up @@ -154,14 +155,14 @@ public string PrivateConfiguration
}
}

public StorageManagementClient StorageClient
public IStorageManagementClient StorageClient
{
get
{
if (this.storageClient == null)
{
this.storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
DefaultProfile.Context, AzureEnvironment.Endpoint.ServiceManagement);
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
}

return this.storageClient;
Expand Down Expand Up @@ -201,14 +202,12 @@ protected string GetStorageKey()

if (!string.IsNullOrEmpty(StorageAccountName))
{
var storageAccount = this.StorageClient.StorageAccounts.Get(StorageAccountName);
if (storageAccount != null)
var storageAccountKeys =
this.StorageClient.StorageAccounts.ListKeys(this.ResourceGroupName,
this.StorageContext.StorageAccountName);
if (storageAccountKeys != null)
{
var keys = this.StorageClient.StorageAccounts.GetKeys(StorageAccountName);
if (keys != null)
{
storageKey = !string.IsNullOrEmpty(keys.PrimaryKey) ? keys.PrimaryKey : keys.SecondaryKey;
}
storageKey = !string.IsNullOrEmpty(storageAccountKeys.StorageAccountKeys.Key1) ? storageAccountKeys.StorageAccountKeys.Key1 : storageAccountKeys.StorageAccountKeys.Key2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use StorageUtilities.GenerateStorageCredentials to get the key instead

}
}

Expand Down