2121using Microsoft . Azure . Management . Compute . Models ;
2222using Microsoft . WindowsAzure . Commands . Common . Storage ;
2323using Microsoft . WindowsAzure . Commands . Utilities . Common ;
24- using Microsoft . WindowsAzure . Management . Storage ;
24+ using Microsoft . Azure . Commands . Management . Storage ;
25+ using Microsoft . Azure . Management . Storage ;
2526using Newtonsoft . Json ;
2627
2728namespace 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