12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
+ using Microsoft . Azure . Common . Authentication ;
15
16
using Microsoft . Azure . Common . Authentication . Models ;
16
17
using Microsoft . Azure . Commands . Compute . Common ;
17
18
using Microsoft . Azure . Commands . Compute . Models ;
@@ -208,14 +209,7 @@ public override void ExecuteCmdlet()
208
209
Hashtable publicSettings = new Hashtable ( ) ;
209
210
publicSettings . Add ( commandToExecuteKey , commandToExecute ?? "" ) ;
210
211
publicSettings . Add ( fileUrisKey , FileUri ?? new string [ ] { } ) ;
211
-
212
- Hashtable privateSettings = new Hashtable ( ) ;
213
- privateSettings . Add ( storageAccountNameKey , StorageAccountName ?? "" ) ;
214
- privateSettings . Add ( storageAccountKeyKey , StorageAccountKey ?? "" ) ;
215
-
216
212
var SettingString = JsonConvert . SerializeObject ( publicSettings ) ;
217
- var ProtectedSettingString = JsonConvert . SerializeObject ( privateSettings ) ;
218
-
219
213
220
214
var parameters = new VirtualMachineExtension
221
215
{
@@ -226,7 +220,7 @@ public override void ExecuteCmdlet()
226
220
ExtensionType = VirtualMachineCustomScriptExtensionContext . ExtensionDefaultName ,
227
221
TypeHandlerVersion = ( this . TypeHandlerVersion ) ?? VirtualMachineCustomScriptExtensionContext . ExtensionDefaultVersion ,
228
222
Settings = SettingString ,
229
- ProtectedSettings = ProtectedSettingString ,
223
+ ProtectedSettings = GetPrivateConfiguration ( ) ,
230
224
} ;
231
225
232
226
var op = this . VirtualMachineExtensionClient . CreateOrUpdate (
@@ -292,5 +286,19 @@ protected string GetSasUrlStr(string storageName, string storageKey, string cont
292
286
return cloudBlob . Uri + sasToken ;
293
287
}
294
288
289
+ protected string GetPrivateConfiguration ( )
290
+ {
291
+ if ( string . IsNullOrEmpty ( this . StorageAccountName ) || string . IsNullOrEmpty ( this . StorageAccountKey ) )
292
+ {
293
+ return string . Empty ;
294
+ }
295
+ else
296
+ {
297
+ var privateSettings = new Hashtable ( ) ;
298
+ privateSettings . Add ( storageAccountNameKey , StorageAccountName ) ;
299
+ privateSettings . Add ( storageAccountKeyKey , StorageAccountKey ) ;
300
+ return JsonUtilities . TryFormatJson ( JsonConvert . SerializeObject ( privateSettings ) ) ;
301
+ }
302
+ }
295
303
}
296
304
}
0 commit comments