Skip to content

Commit f541414

Browse files
unknownunknown
authored andcommitted
Fix CustomScript extension for SASUri.
1 parent c8898d4 commit f541414

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/CustomScript/SetAzureVMCustomScriptExtensionCommand.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Common.Authentication;
1516
using Microsoft.Azure.Common.Authentication.Models;
1617
using Microsoft.Azure.Commands.Compute.Common;
1718
using Microsoft.Azure.Commands.Compute.Models;
@@ -208,14 +209,7 @@ public override void ExecuteCmdlet()
208209
Hashtable publicSettings = new Hashtable();
209210
publicSettings.Add(commandToExecuteKey, commandToExecute ?? "");
210211
publicSettings.Add(fileUrisKey, FileUri ?? new string[] { });
211-
212-
Hashtable privateSettings = new Hashtable();
213-
privateSettings.Add(storageAccountNameKey, StorageAccountName ?? "");
214-
privateSettings.Add(storageAccountKeyKey, StorageAccountKey ?? "");
215-
216212
var SettingString = JsonConvert.SerializeObject(publicSettings);
217-
var ProtectedSettingString = JsonConvert.SerializeObject(privateSettings);
218-
219213

220214
var parameters = new VirtualMachineExtension
221215
{
@@ -226,7 +220,7 @@ public override void ExecuteCmdlet()
226220
ExtensionType = VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName,
227221
TypeHandlerVersion = (this.TypeHandlerVersion) ?? VirtualMachineCustomScriptExtensionContext.ExtensionDefaultVersion,
228222
Settings = SettingString,
229-
ProtectedSettings = ProtectedSettingString,
223+
ProtectedSettings = GetPrivateConfiguration(),
230224
};
231225

232226
var op = this.VirtualMachineExtensionClient.CreateOrUpdate(
@@ -292,5 +286,19 @@ protected string GetSasUrlStr(string storageName, string storageKey, string cont
292286
return cloudBlob.Uri + sasToken;
293287
}
294288

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+
}
295303
}
296304
}

0 commit comments

Comments
 (0)