Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Compute SDK Changes for ProtectedSettingsFromKeyVault #25620

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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