Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 57614ef

Browse files
LuyunmtTianyun-G
andauthored
Change key vault to track2 (#2)
* change key vault to track2 * Update packages version * Update code according to comments * Update code to sync Co-authored-by: Tianyun Gao <v-tianga@microsoft.com>
1 parent df66ca8 commit 57614ef

File tree

6 files changed

+108
-59
lines changed

6 files changed

+108
-59
lines changed

Asset/documentdb-dotnet-todo-app/src/DocumentDBRepository.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ namespace todo
77
{
88
using System;
99
using System.Collections.Generic;
10+
using System.Collections.ObjectModel;
1011
using System.Configuration;
1112
using System.Linq;
1213
using System.Linq.Expressions;
14+
using System.Threading;
1315
using System.Threading.Tasks;
16+
using Azure.Identity;
17+
using Azure.Security.KeyVault.Secrets;
1418
using Microsoft.Azure.Documents;
1519
using Microsoft.Azure.Documents.Client;
1620
using Microsoft.Azure.Documents.Linq;
17-
using System.Collections.ObjectModel;
18-
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
19-
using Microsoft.Azure.KeyVault;
20-
using System.Threading;
2121

2222
public static class DocumentDBRepository<T> where T : class
2323
{
@@ -81,14 +81,11 @@ public static async Task DeleteItemAsync(string id, string category)
8181

8282
public static void Initialize()
8383
{
84-
var factory = new MSITokenProviderFactory(new MSILoginInformation(MSIResourceType.AppService));
85-
KeyVaultClient kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(async (authority, resource, scope) =>
86-
{
87-
return (await factory.Create(resource).GetAuthenticationHeaderAsync(default(CancellationToken))).Parameter;
88-
}));
84+
var credential = new DefaultAzureCredential();
8985
var vaultBaseUrl = Environment.GetEnvironmentVariable("AZURE_KEYVAULT_URI");
90-
var endpoint = kvClient.GetSecretAsync(vaultBaseUrl, "azure-documentdb-uri").GetAwaiter().GetResult().Value;
91-
var authKey = kvClient.GetSecretAsync(vaultBaseUrl, "azure-documentdb-key").GetAwaiter().GetResult().Value;
86+
SecretClient secretClient = new SecretClient(new Uri(vaultBaseUrl),credential);
87+
var endpoint = secretClient.GetSecret("azure-documentdb-uri").Value.Value;
88+
var authKey = secretClient.GetSecret("azure-documentdb-key").Value.Value;
9289
client = new DocumentClient(new Uri(endpoint), authKey);
9390
CreateDatabaseIfNotExistsAsync().Wait();
9491
CreateCollectionIfNotExistsAsync().Wait();

Asset/documentdb-dotnet-todo-app/src/Web.config

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
</system.Web>
2222
-->
2323
<system.web>
24-
<compilation debug="true" targetFramework="4.5.2" />
24+
<compilation debug="true" targetFramework="4.7.2" />
2525
<httpRuntime targetFramework="4.5" />
26-
<customErrors mode="Off"/>
26+
<customErrors mode="Off" />
2727
</system.web>
2828
<runtime>
2929
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@@ -55,6 +55,30 @@
5555
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
5656
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
5757
</dependentAssembly>
58+
<dependentAssembly>
59+
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
60+
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
61+
</dependentAssembly>
62+
<dependentAssembly>
63+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
64+
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
65+
</dependentAssembly>
66+
<dependentAssembly>
67+
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
68+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
69+
</dependentAssembly>
70+
<dependentAssembly>
71+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
72+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
73+
</dependentAssembly>
74+
<dependentAssembly>
75+
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
76+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
77+
</dependentAssembly>
78+
<dependentAssembly>
79+
<assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
80+
<bindingRedirect oldVersion="0.0.0.0-1.19.0.0" newVersion="1.19.0.0" />
81+
</dependentAssembly>
5882
</assemblyBinding>
5983
</runtime>
6084
</configuration>

Asset/documentdb-dotnet-todo-app/src/packages.config

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
4+
<package id="Azure.Core" version="1.19.0" targetFramework="net472" />
5+
<package id="Azure.Identity" version="1.4.1" targetFramework="net472" />
6+
<package id="Azure.Security.KeyVault.Secrets" version="4.2.0" targetFramework="net472" />
47
<package id="bootstrap" version="3.2.0" targetFramework="net45" />
58
<package id="EntityFramework" version="6.1.2-beta1" targetFramework="net45" />
69
<package id="jQuery" version="2.1.1" targetFramework="net45" />
@@ -12,12 +15,26 @@
1215
<package id="Microsoft.Azure.DocumentDB" version="1.6.1" targetFramework="net45" />
1316
<package id="Microsoft.Azure.KeyVault" version="2.3.2" targetFramework="net452" />
1417
<package id="Microsoft.Azure.KeyVault.WebKey" version="2.0.7" targetFramework="net452" />
18+
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net472" />
19+
<package id="Microsoft.Identity.Client" version="4.30.1" targetFramework="net472" />
20+
<package id="Microsoft.Identity.Client.Extensions.Msal" version="2.18.4" targetFramework="net472" />
1521
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.2" targetFramework="net45" />
1622
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
1723
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
1824
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
1925
<package id="Modernizr" version="2.8.3" targetFramework="net45" />
2026
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
2127
<package id="Respond" version="1.4.2" targetFramework="net45" />
28+
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
29+
<package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net472" />
30+
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
31+
<package id="System.Memory.Data" version="1.0.2" targetFramework="net472" />
32+
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
33+
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net472" />
34+
<package id="System.Security.Cryptography.ProtectedData" version="4.5.0" targetFramework="net472" />
35+
<package id="System.Text.Encodings.Web" version="4.7.2" targetFramework="net472" />
36+
<package id="System.Text.Json" version="4.6.0" targetFramework="net472" />
37+
<package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net472" />
38+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
2239
<package id="WebGrease" version="1.6.0" targetFramework="net45" />
2340
</packages>

Asset/documentdb-dotnet-todo-app/src/todo.csproj

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AppDesignerFolder>Properties</AppDesignerFolder>
1414
<RootNamespace>todo</RootNamespace>
1515
<AssemblyName>todo</AssemblyName>
16-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
16+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1717
<MvcBuildViews>false</MvcBuildViews>
1818
<UseIISExpress>true</UseIISExpress>
1919
<IISExpressSSLPort />
@@ -25,6 +25,7 @@
2525
<NuGetPackageImportStamp>
2626
</NuGetPackageImportStamp>
2727
<TargetFrameworkProfile />
28+
<Use64BitIISExpress />
2829
</PropertyGroup>
2930
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3031
<DebugSymbols>true</DebugSymbols>
@@ -48,6 +49,15 @@
4849
<SpecificVersion>False</SpecificVersion>
4950
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
5051
</Reference>
52+
<Reference Include="Azure.Core, Version=1.19.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
53+
<HintPath>..\packages\Azure.Core.1.19.0\lib\net461\Azure.Core.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Azure.Identity, Version=1.4.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
56+
<HintPath>..\packages\Azure.Identity.1.4.1\lib\netstandard2.0\Azure.Identity.dll</HintPath>
57+
</Reference>
58+
<Reference Include="Azure.Security.KeyVault.Secrets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Azure.Security.KeyVault.Secrets.4.2.0\lib\netstandard2.0\Azure.Security.KeyVault.Secrets.dll</HintPath>
60+
</Reference>
5161
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
5262
<SpecificVersion>False</SpecificVersion>
5363
<HintPath>..\packages\EntityFramework.6.1.2-beta1\lib\net45\EntityFramework.dll</HintPath>
@@ -60,13 +70,19 @@
6070
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.6.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
6171
<Private>True</Private>
6272
</Reference>
63-
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64-
<HintPath>..\packages\Microsoft.Azure.KeyVault.2.3.2\lib\net452\Microsoft.Azure.KeyVault.dll</HintPath>
65-
</Reference>
6673
<Reference Include="Microsoft.Azure.KeyVault.WebKey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6774
<HintPath>..\packages\Microsoft.Azure.KeyVault.WebKey.2.0.7\lib\net452\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
6875
</Reference>
76+
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
77+
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
78+
</Reference>
6979
<Reference Include="Microsoft.CSharp" />
80+
<Reference Include="Microsoft.Identity.Client, Version=4.30.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
81+
<HintPath>..\packages\Microsoft.Identity.Client.4.30.1\lib\net461\Microsoft.Identity.Client.dll</HintPath>
82+
</Reference>
83+
<Reference Include="Microsoft.Identity.Client.Extensions.Msal, Version=2.18.4.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
84+
<HintPath>..\packages\Microsoft.Identity.Client.Extensions.Msal.2.18.4\lib\net45\Microsoft.Identity.Client.Extensions.Msal.dll</HintPath>
85+
</Reference>
7086
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7187
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.8\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
7288
</Reference>
@@ -78,9 +94,45 @@
7894
<Private>True</Private>
7995
</Reference>
8096
<Reference Include="System" />
97+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
98+
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
99+
</Reference>
81100
<Reference Include="System.Data" />
82101
<Reference Include="System.Data.DataSetExtensions" />
102+
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
103+
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.6.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
104+
</Reference>
83105
<Reference Include="System.Drawing" />
106+
<Reference Include="System.IdentityModel" />
107+
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
108+
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
109+
</Reference>
110+
<Reference Include="System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
111+
<HintPath>..\packages\System.Memory.Data.1.0.2\lib\net461\System.Memory.Data.dll</HintPath>
112+
</Reference>
113+
<Reference Include="System.Numerics" />
114+
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
115+
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
116+
</Reference>
117+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
118+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
119+
</Reference>
120+
<Reference Include="System.Security" />
121+
<Reference Include="System.Security.Cryptography.ProtectedData, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
122+
<HintPath>..\packages\System.Security.Cryptography.ProtectedData.4.5.0\lib\net461\System.Security.Cryptography.ProtectedData.dll</HintPath>
123+
</Reference>
124+
<Reference Include="System.Text.Encodings.Web, Version=4.0.5.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
125+
<HintPath>..\packages\System.Text.Encodings.Web.4.7.2\lib\net461\System.Text.Encodings.Web.dll</HintPath>
126+
</Reference>
127+
<Reference Include="System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
128+
<HintPath>..\packages\System.Text.Json.4.6.0\lib\net461\System.Text.Json.dll</HintPath>
129+
</Reference>
130+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
131+
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
132+
</Reference>
133+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
134+
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
135+
</Reference>
84136
<Reference Include="System.Web.DynamicData" />
85137
<Reference Include="System.Web.Entity" />
86138
<Reference Include="System.Web.ApplicationServices" />
@@ -113,6 +165,7 @@
113165
<Reference Include="System.Web" />
114166
<Reference Include="System.Web.Abstractions" />
115167
<Reference Include="System.Web.Routing" />
168+
<Reference Include="System.Windows.Forms" />
116169
<Reference Include="System.Xml" />
117170
<Reference Include="System.Configuration" />
118171
<Reference Include="System.Web.Services" />
@@ -207,12 +260,6 @@
207260
<SubType>Designer</SubType>
208261
</Content>
209262
</ItemGroup>
210-
<ItemGroup>
211-
<ProjectReference Include="..\..\azure-libraries-for-net\src\ResourceManagement\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj">
212-
<Project>{c67ba3ec-f895-4232-91cd-6af5f5847072}</Project>
213-
<Name>Microsoft.Azure.Management.ResourceManager.Fluent</Name>
214-
</ProjectReference>
215-
</ItemGroup>
216263
<PropertyGroup>
217264
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
218265
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

Common/Utilities.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
using Microsoft.Azure.Management.Search.Fluent;
3434
using Microsoft.Azure.Management.Search.Fluent.Models;
3535
using Microsoft.Azure.Management.ServiceBus.Fluent;
36-
using Microsoft.Azure.ServiceBus;
3736
using System.Threading;
3837
using System.Net.Http.Headers;
3938
using Microsoft.Azure.Management.BatchAI.Fluent;
@@ -2980,38 +2979,6 @@ public static string GetCertificatePath(string certificateName)
29802979
return Path.Combine(Utilities.ProjectPath, "Asset", certificateName);
29812980
}
29822981

2983-
public static void SendMessageToTopic(string connectionString, string topicName, string message)
2984-
{
2985-
if (!IsRunningMocked)
2986-
{
2987-
try
2988-
{
2989-
var topicClient = new TopicClient(connectionString, topicName);
2990-
topicClient.SendAsync(new Message(Encoding.UTF8.GetBytes(message))).Wait();
2991-
topicClient.Close();
2992-
}
2993-
catch (Exception)
2994-
{
2995-
}
2996-
}
2997-
}
2998-
2999-
public static void SendMessageToQueue(string connectionString, string queueName, string message)
3000-
{
3001-
if (!IsRunningMocked)
3002-
{
3003-
try
3004-
{
3005-
var queueClient = new QueueClient(connectionString, queueName, ReceiveMode.PeekLock);
3006-
queueClient.SendAsync(new Message(Encoding.UTF8.GetBytes(message))).Wait();
3007-
queueClient.Close();
3008-
}
3009-
catch (Exception)
3010-
{
3011-
}
3012-
}
3013-
}
3014-
30152982
private static string TrySsh(
30162983
string host,
30172984
int port,

CreateCosmosDBWithIPRange.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
<ItemGroup>
2121
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.18" />
2222
<PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.24.0" />
23-
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
2423
<PackageReference Include="CoreFTP" Version="1.2.0" />
25-
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.2-preview" />
2624
<PackageReference Include="SSH.NET" Version="2016.0.0" />
2725
<PackageReference Include="Docker.DotNet" Version="2.124.3" />
2826
<PackageReference Include="Docker.DotNet.X509" Version="2.124.3" />
29-
<PackageReference Include="WindowsAzure.Storage" Version="8.1.4" />
3027
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
3128
</ItemGroup>
3229

0 commit comments

Comments
 (0)