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

Commit 3a5dab6

Browse files
author
Christy Henriksson
authored
Update Gallery.CredentialExpiration to use SqlConnectionFactory (#419)
1 parent 88bd59d commit 3a5dab6

4 files changed

Lines changed: 51 additions & 101 deletions

File tree

src/Gallery.CredentialExpiration/App.config

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
55
</startup>
66
<runtime>
77
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
88
<dependentAssembly>
9-
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
10-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
9+
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
10+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1111
</dependentAssembly>
1212
<dependentAssembly>
13-
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
13+
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
14+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1515
</dependentAssembly>
1616
<dependentAssembly>
17-
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
18-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
17+
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
18+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
1919
</dependentAssembly>
2020
<dependentAssembly>
21-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
22-
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
21+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
22+
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
2323
</dependentAssembly>
2424
<dependentAssembly>
25-
<assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
26-
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
25+
<assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral"/>
26+
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
2727
</dependentAssembly>
2828
<dependentAssembly>
29-
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
30-
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
29+
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
30+
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0"/>
3131
</dependentAssembly>
3232
<dependentAssembly>
33-
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
34-
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
35-
</dependentAssembly>
36-
<dependentAssembly>
37-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
38-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
39-
</dependentAssembly>
40-
<dependentAssembly>
41-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
42-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
43-
</dependentAssembly>
44-
<dependentAssembly>
45-
<assemblyIdentity name="NuGet.Services.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
46-
<bindingRedirect oldVersion="0.0.0.0-2.2.3.0" newVersion="2.2.3.0" />
33+
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
34+
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0"/>
4735
</dependentAssembly>
4836
</assemblyBinding>
4937
</runtime>
Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Gallery.CredentialExpiration</RootNamespace>
1111
<AssemblyName>Gallery.CredentialExpiration</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1415
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -33,40 +34,9 @@
3334
<WarningLevel>4</WarningLevel>
3435
</PropertyGroup>
3536
<ItemGroup>
36-
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
37-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
38-
</Reference>
39-
<Reference Include="Microsoft.Data.Edm, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
40-
<HintPath>..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
41-
<Private>True</Private>
42-
</Reference>
43-
<Reference Include="Microsoft.Data.OData, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
44-
<HintPath>..\..\packages\Microsoft.Data.OData.5.6.4\lib\net40\Microsoft.Data.OData.dll</HintPath>
45-
<Private>True</Private>
46-
</Reference>
47-
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.6.4\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
49-
<Private>True</Private>
50-
</Reference>
51-
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
52-
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
53-
</Reference>
54-
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55-
<HintPath>..\..\packages\WindowsAzure.Storage.7.1.2\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
56-
</Reference>
57-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
58-
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
59-
</Reference>
60-
<Reference Include="NuGet.Services.Storage, Version=2.1.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61-
<HintPath>..\..\packages\NuGet.Services.Storage.2.1.3\lib\net452\NuGet.Services.Storage.dll</HintPath>
62-
</Reference>
6337
<Reference Include="System" />
6438
<Reference Include="System.ComponentModel.Composition" />
6539
<Reference Include="System.Core" />
66-
<Reference Include="System.Spatial, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
67-
<HintPath>..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll</HintPath>
68-
<Private>True</Private>
69-
</Reference>
7040
<Reference Include="System.Xml.Linq" />
7141
<Reference Include="System.Data.DataSetExtensions" />
7242
<Reference Include="Microsoft.CSharp" />
@@ -88,11 +58,10 @@
8858
</Compile>
8959
</ItemGroup>
9060
<ItemGroup>
91-
<None Include="App.config" />
92-
<None Include="Gallery.CredentialExpiration.nuspec">
61+
<None Include="App.config">
9362
<SubType>Designer</SubType>
9463
</None>
95-
<None Include="packages.config">
64+
<None Include="Gallery.CredentialExpiration.nuspec">
9665
<SubType>Designer</SubType>
9766
</None>
9867
<None Include="Scripts\*" />
@@ -110,13 +79,29 @@
11079
<SubType>Designer</SubType>
11180
</EmbeddedResource>
11281
</ItemGroup>
82+
<ItemGroup>
83+
<PackageReference Include="Microsoft.Data.Edm">
84+
<Version>5.7.0</Version>
85+
</PackageReference>
86+
<PackageReference Include="Microsoft.Data.OData">
87+
<Version>5.7.0</Version>
88+
</PackageReference>
89+
<PackageReference Include="Microsoft.Data.Services.Client">
90+
<Version>5.7.0</Version>
91+
</PackageReference>
92+
<PackageReference Include="Newtonsoft.Json">
93+
<Version>9.0.1</Version>
94+
</PackageReference>
95+
<PackageReference Include="NuGet.Services.Sql">
96+
<Version>2.25.0-master-30263</Version>
97+
</PackageReference>
98+
<PackageReference Include="NuGet.Services.Storage">
99+
<Version>2.1.3</Version>
100+
</PackageReference>
101+
<PackageReference Include="WindowsAzure.Storage">
102+
<Version>7.1.2</Version>
103+
</PackageReference>
104+
</ItemGroup>
113105
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
114106
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
115-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
116-
Other similar extension points exist, see Microsoft.Common.targets.
117-
<Target Name="BeforeBuild">
118-
</Target>
119-
<Target Name="AfterBuild">
120-
</Target>
121-
-->
122107
</Project>

src/Gallery.CredentialExpiration/Job.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using Microsoft.WindowsAzure.Storage;
1717
using Newtonsoft.Json;
1818
using NuGet.Jobs;
19+
using NuGet.Services.KeyVault;
20+
using NuGet.Services.Sql;
1921
using NuGet.Services.Storage;
2022

2123
namespace Gallery.CredentialExpiration
@@ -32,7 +34,7 @@ public class Job : JobBase
3234
private string _galleryBrand;
3335
private string _galleryAccountUrl;
3436

35-
private SqlConnectionStringBuilder _galleryDatabase;
37+
private ISqlConnectionFactory _galleryDatabase;
3638

3739
private string _mailFrom;
3840
private SmtpClient _smtpClient;
@@ -46,8 +48,9 @@ public override void Init(IServiceContainer serviceContainer, IDictionary<string
4648
{
4749
_whatIf = JobConfigurationManager.TryGetBoolArgument(jobArgsDictionary, JobArgumentNames.WhatIf);
4850

51+
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
4952
var databaseConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.GalleryDatabase);
50-
_galleryDatabase = new SqlConnectionStringBuilder(databaseConnectionString);
53+
_galleryDatabase = new AzureSqlConnectionFactory(databaseConnectionString, secretInjector);
5154

5255
_galleryBrand = JobConfigurationManager.GetArgument(jobArgsDictionary, MyJobArgumentNames.GalleryBrand);
5356
_galleryAccountUrl = JobConfigurationManager.GetArgument(jobArgsDictionary, MyJobArgumentNames.GalleryAccountUrl);
@@ -94,12 +97,11 @@ public override async Task Run()
9497
}
9598

9699
// Connect to database
97-
using (var galleryConnection = await _galleryDatabase.ConnectTo())
100+
using (var galleryConnection = await _galleryDatabase.CreateAsync())
98101
{
99102
// Fetch credentials that expire in _warnDaysBeforeExpiration days
100103
// + the user's e-mail address
101-
Logger.LogInformation("Retrieving expired credentials from {InitialCatalog}...",
102-
_galleryDatabase.InitialCatalog);
104+
Logger.LogInformation("Retrieving expired credentials from Gallery database...");
103105

104106
expiredCredentials = (await galleryConnection.QueryWithRetryAsync<ExpiredCredentialData>(
105107
Strings.GetExpiredCredentialsQuery,

src/Gallery.CredentialExpiration/packages.config

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)