Skip to content

Commit

Permalink
Key Vault convenience for data plane (V3) (#520)
Browse files Browse the repository at this point in the history
* Add access to data plane key vault client

* Secrets collection

* Key collection

* Key & Secret fluent

* Support authenticating to Key Vault

* Code Cleanup

* fixed build

* Fixed runtime issues

* Fixed KV source file formatting.

* Removed code comment.

* Support getting by name & version in key vault

* Support auth files without key vault endpoint
  • Loading branch information
hovsepm authored Dec 4, 2018
1 parent 41315f0 commit 4ffeb07
Show file tree
Hide file tree
Showing 58 changed files with 4,930 additions and 504 deletions.
4 changes: 2 additions & 2 deletions Samples/Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.3.2" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.15" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.17" />
<PackageReference Include="CoreFTP" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.2-preview" />
<PackageReference Include="SSH.NET" Version="2016.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions Samples/Sql/ManageSqlServerKeysWithAzureKeyVaultKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public static void RunSample(IAzure azure)
Utilities.Log("Creating a SQL server key with Azure Key Vault key");

KeyVaultClient kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken));
var keyBundle = kvClient.CreateKeyAsync(vault.VaultUri, keyName, JsonWebKeyType.Rsa,
keyOps: JsonWebKeyOperation.AllOperations).GetAwaiter().GetResult();
var keyBundle = kvClient.CreateKeyAsync(vault.VaultUri, keyName, Microsoft.Azure.KeyVault.WebKey.JsonWebKeyType.Rsa,
keyOps: Microsoft.Azure.KeyVault.WebKey.JsonWebKeyOperation.AllOperations).GetAwaiter().GetResult();

string keyUri = keyBundle.Key.Kid;

Expand Down
102 changes: 102 additions & 0 deletions Tests/Fluent.Tests/KeyVault/SecretTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Fluent.Tests.Common;
using Microsoft.Azure.Management.KeyVault.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.KeyVault.Fluent.Models;
using System.Linq;
using Xunit;
using System;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Azure.Tests;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.Graph.RBAC.Fluent;
using System.Collections.Generic;

namespace Fluent.Tests
{

public class Secrets
{

/**
* Main entry point.
* @param args the parameters
*/
[Fact]
public void CanCRUDSecret()
{
using (var context = FluentMockContext.Start(GetType().FullName))
{
IGraphRbacManager graphManager = TestHelper.CreateGraphRbacManager();
string vaultName1 = TestUtilities.GenerateName("vault1");
string secretName = TestUtilities.GenerateName("secret1");
string rgName = TestUtilities.GenerateName("rgNEMV");

IKeyVaultManager manager = TestHelper.CreateKeyVaultManager();

var spnCredentialsClientId = HttpMockServer.Variables[ConnectionStringKeys.ServicePrincipalKey];

try
{
IVault vault = manager.Vaults
.Define(vaultName1)
.WithRegion(Region.USWest)
.WithNewResourceGroup(rgName)
.DefineAccessPolicy()
.ForServicePrincipal(spnCredentialsClientId)
.AllowKeyAllPermissions()
.AllowSecretAllPermissions()
.Attach()
.Create();
Assert.NotNull(vault);

SdkContext.DelayProvider.Delay(10000);

var secret = vault.Secrets.Define(secretName)
.WithValue("Some secret value")
.Create();

Assert.NotNull(secret);
Assert.NotNull(secret.Id);
Assert.Equal("Some secret value", secret.Value);

secret = secret.Update()
.WithValue("Some updated value")
.Apply();

Assert.Equal("Some updated value", secret.Value);

var versions = secret.ListVersions();

int count = 2;
foreach (var version in versions)
{
if ("Some secret value" == version.Value)
{
count--;
}
if ("Some updated value" == version.Value)
{
count--;
}
}
Assert.Equal(0, count);

}
finally
{
try
{
TestHelper.CreateResourceManager().ResourceGroups.DeleteByName(rgName);
}
catch { }
}
}
}

}
}
Loading

0 comments on commit 4ffeb07

Please sign in to comment.