Skip to content

Commit 8d44f81

Browse files
committed
Merge pull request #1112 from rahulpandit85/dev
Use V2 Storage accounts for RM based Diagnostics Extenstion
2 parents 93edfa5 + 5c679fd commit 8d44f81

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/Diagnostics/SetAzureVMDiagnosticsExtension.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
using Microsoft.Azure.Management.Compute.Models;
2222
using Microsoft.WindowsAzure.Commands.Common.Storage;
2323
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24-
using Microsoft.WindowsAzure.Management.Storage;
24+
using Microsoft.Azure.Commands.Management.Storage;
25+
using Microsoft.Azure.Management.Storage;
2526
using Newtonsoft.Json;
2627

2728
namespace Microsoft.Azure.Commands.Compute
@@ -37,7 +38,7 @@ public class SetAzureVMDiagnosticsExtensionCommand : VirtualMachineExtensionBase
3738
private const string VirtualMachineExtension = "Microsoft.Compute/virtualMachines/extensions";
3839
private const string IaaSDiagnosticsExtension = "IaaSDiagnostics";
3940
private const string ExtensionPublisher = "Microsoft.Azure.Diagnostics";
40-
private StorageManagementClient storageClient;
41+
private IStorageManagementClient storageClient;
4142

4243
[Parameter(
4344
Mandatory = true,
@@ -154,14 +155,14 @@ public string PrivateConfiguration
154155
}
155156
}
156157

157-
public StorageManagementClient StorageClient
158+
public IStorageManagementClient StorageClient
158159
{
159160
get
160161
{
161162
if (this.storageClient == null)
162163
{
163164
this.storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
164-
DefaultProfile.Context, AzureEnvironment.Endpoint.ServiceManagement);
165+
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
165166
}
166167

167168
return this.storageClient;
@@ -201,15 +202,8 @@ protected string GetStorageKey()
201202

202203
if (!string.IsNullOrEmpty(StorageAccountName))
203204
{
204-
var storageAccount = this.StorageClient.StorageAccounts.Get(StorageAccountName);
205-
if (storageAccount != null)
206-
{
207-
var keys = this.StorageClient.StorageAccounts.GetKeys(StorageAccountName);
208-
if (keys != null)
209-
{
210-
storageKey = !string.IsNullOrEmpty(keys.PrimaryKey) ? keys.PrimaryKey : keys.SecondaryKey;
211-
}
212-
}
205+
var storageCredentials = StorageUtilities.GenerateStorageCredentials(this.StorageClient, this.ResourceGroupName, this.StorageAccountName);
206+
storageKey = storageCredentials.ExportBase64EncodedKey();
213207
}
214208

215209
return storageKey;

0 commit comments

Comments
 (0)