Skip to content

Commit

Permalink
init (#25620)
Browse files Browse the repository at this point in the history
Co-authored-by: Theodore Chang <thchan@microsoft.com>
  • Loading branch information
kamusta-msft and grizzlytheodore authored Jan 14, 2022
1 parent 5278e55 commit 2f450af
Show file tree
Hide file tree
Showing 8 changed files with 1,028 additions and 566 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Compute.Tests
Expand Down Expand Up @@ -114,6 +116,20 @@ public void TestVMExtensionOperations()

// Validate the extension delete API
m_CrpClient.VirtualMachineExtensions.Delete(rgName, vm.Name, vmExtension.Name);

// Add another extension to the VM with protectedSettingsFromKeyVault
var vmExtension2 = GetTestVMExtension();
AddProtectedSettingsFromKeyVaultToExtension(vmExtension2, rgName);

//For now we just validate that the protectedSettingsFromKeyVault has been accepted and persisted. Since we didn't create a KV, this failure is expected
try
{
response = m_CrpClient.VirtualMachineExtensions.CreateOrUpdate(rgName, vm.Name, vmExtension2.Name, vmExtension2);
}
catch (Exception e)
{
Assert.Contains("either has not been enabled for deployment or the vault id provided", e.Message);
}
}
finally
{
Expand Down Expand Up @@ -146,6 +162,16 @@ private void ValidateVMExtensionInstanceView(VirtualMachineExtensionInstanceView
Assert.NotNull(vmExtInstanceView.Statuses[0].Level);
Assert.NotNull(vmExtInstanceView.Statuses[0].Message);
}

private void AddProtectedSettingsFromKeyVaultToExtension(VirtualMachineExtension vmExtension, string resourceGroupName)
{
vmExtension.ProtectedSettings = null;
string idValue = string.Format("subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.KeyVault/vaults/kvName", m_subId, resourceGroupName);
string sourceVaultId = string.Format("\"id\": \"{0}\"", idValue);
string sourceVault = "{ " + sourceVaultId + " }";
string secret = string.Format("\"secretUrl\": \"{0}\"", "https://kvName.vault.azure.net/secrets/secretName/79b88b3a6f5440ffb2e73e44a0db712e");
vmExtension.ProtectedSettingsFromKeyVault = new JRaw("{ " + string.Format("\"sourceVault\": {0},{1}", sourceVault, secret) + " }");
}
}
}

Loading

0 comments on commit 2f450af

Please sign in to comment.