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

Commit cd322cd

Browse files
author
Christy Henriksson
authored
SQL auto-rotation: UpdateLicenseReports (#420)
1 parent 3a5dab6 commit cd322cd

4 files changed

Lines changed: 49 additions & 128 deletions

File tree

src/UpdateLicenseReports/App.config

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
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.OData" 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.OData" 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="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
13+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
14+
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
1515
</dependentAssembly>
1616
<dependentAssembly>
17-
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
18-
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
17+
<assemblyIdentity name="Microsoft.Azure.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
18+
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0"/>
1919
</dependentAssembly>
2020
<dependentAssembly>
21-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
22-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
21+
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
22+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
2323
</dependentAssembly>
2424
<dependentAssembly>
25-
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
26-
<bindingRedirect oldVersion="0.0.0.0-3.13.4.878" newVersion="3.13.4.878" />
25+
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
26+
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0"/>
2727
</dependentAssembly>
2828
<dependentAssembly>
29-
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
30-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
31-
</dependentAssembly>
32-
<dependentAssembly>
33-
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
34-
<bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
35-
</dependentAssembly>
36-
<dependentAssembly>
37-
<assemblyIdentity name="NuGet.Services.KeyVault" publicKeyToken="31bf3856ad364e35" culture="neutral" />
38-
<bindingRedirect oldVersion="0.0.0.0-2.2.3.0" newVersion="2.2.3.0" />
39-
</dependentAssembly>
40-
<dependentAssembly>
41-
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
42-
<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"/>
4331
</dependentAssembly>
4432
</assemblyBinding>
4533
</runtime>

src/UpdateLicenseReports/UpdateLicenseReports.Job.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.ComponentModel.Design;
77
using System.Data;
8-
using System.Data.SqlClient;
98
using System.IO;
109
using System.Linq;
1110
using System.Net;
@@ -15,13 +14,15 @@
1514
using Newtonsoft.Json.Linq;
1615
using Newtonsoft.Json.Schema;
1716
using NuGet.Jobs;
17+
using NuGet.Services.KeyVault;
18+
using NuGet.Services.Sql;
1819

1920
namespace UpdateLicenseReports
2021
{
2122
internal class Job : JobBase
2223
{
2324
private const int _defaultRetryCount = 4;
24-
private static readonly JsonSchema _sonatypeSchema = JsonSchema.Parse(@"{ 'type': 'object',
25+
private static readonly JSchema _sonatypeSchema = JSchema.Parse(@"{ 'type': 'object',
2526
'properties': {
2627
'next' : { 'type' : 'string' },
2728
'events' : {
@@ -40,7 +41,7 @@ internal class Job : JobBase
4041
private Uri _licenseReportService;
4142
private string _licenseReportUser;
4243
private string _licenseReportPassword;
43-
private SqlConnectionStringBuilder _packageDatabase;
44+
private ISqlConnectionFactory _packageDbConnectionFactory;
4445
private int? _retryCount;
4546
private NetworkCredential _licenseReportCredentials;
4647

@@ -60,8 +61,9 @@ private static PackageLicenseReport CreateReport(JObject messageEvent)
6061

6162
public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary)
6263
{
63-
_packageDatabase = new SqlConnectionStringBuilder(
64-
JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase));
64+
var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
65+
var dbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.PackageDatabase);
66+
_packageDbConnectionFactory = new AzureSqlConnectionFactory(dbConnectionString, secretInjector);
6567

6668
var retryCountString = JobConfigurationManager.TryGetArgument(jobArgsDictionary, JobArgumentNames.RetryCount);
6769
if (string.IsNullOrEmpty(retryCountString))
@@ -109,10 +111,11 @@ public override async Task Run()
109111

110112
private async Task<Uri> FetchNextReportUrlAsync()
111113
{
112-
Logger.LogInformation("Fetching next report URL from {DataSource}/{InitialCatalog}", _packageDatabase.DataSource, _packageDatabase.InitialCatalog);
114+
Logger.LogInformation("Fetching next report URL from {DataSource}/{InitialCatalog}",
115+
_packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
113116

114117
Uri nextLicenseReport = null;
115-
using (var connection = await _packageDatabase.ConnectTo())
118+
using (var connection = await _packageDbConnectionFactory.CreateAsync())
116119
{
117120
var nextReportUrl = (await connection.QueryAsync<string>(
118121
@"SELECT TOP 1 NextLicenseReport FROM GallerySettings")).SingleOrDefault();
@@ -129,7 +132,9 @@ private async Task<Uri> FetchNextReportUrlAsync()
129132
nextLicenseReport = nextLicenseReport ?? _licenseReportService;
130133
}
131134

132-
Logger.LogInformation("Fetched next report URL '{NextReportUrl}' from {DataSource}/{InitialCatalog}", (nextLicenseReport == null ? string.Empty : nextLicenseReport.AbsoluteUri), _packageDatabase.DataSource, _packageDatabase.InitialCatalog);
135+
Logger.LogInformation("Fetched next report URL '{NextReportUrl}' from {DataSource}/{InitialCatalog}",
136+
(nextLicenseReport == null ? string.Empty : nextLicenseReport.AbsoluteUri),
137+
_packageDbConnectionFactory.DataSource, _packageDbConnectionFactory.InitialCatalog);
133138

134139
return nextLicenseReport;
135140
}
@@ -237,7 +242,7 @@ private async Task<bool> ProcessReportsAsync(Uri nextLicenseReport)
237242
Logger.LogInformation("Storing next license report URL: {NextReportUrl}", nextLicenseReport.AbsoluteUri);
238243

239244
// Record the next report to the database so we can check it again if we get aborted before finishing.
240-
using (var connection = await _packageDatabase.ConnectTo())
245+
using (var connection = await _packageDbConnectionFactory.CreateAsync())
241246
{
242247
await connection.QueryAsync<int>(@"
243248
UPDATE GallerySettings
@@ -269,7 +274,7 @@ UPDATE GallerySettings
269274

270275
private async Task<int> StoreReportAsync(PackageLicenseReport report)
271276
{
272-
using (var connection = await _packageDatabase.ConnectTo())
277+
using (var connection = await _packageDbConnectionFactory.CreateAsync())
273278
using (var command = connection.CreateCommand())
274279
{
275280
command.CommandText = "AddPackageLicenseReport2";
Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.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>UpdateLicenseReports</RootNamespace>
1111
<AssemblyName>UpdateLicenseReports</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1415
<TargetFrameworkProfile />
1516
<NuGetPackageImportStamp>
1617
</NuGetPackageImportStamp>
@@ -35,57 +36,12 @@
3536
<WarningLevel>4</WarningLevel>
3637
</PropertyGroup>
3738
<ItemGroup>
38-
<Reference Include="Dapper.StrongName, Version=1.50.2.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3, processorArchitecture=MSIL">
39-
<HintPath>..\..\packages\Dapper.StrongName.1.50.2\lib\net451\Dapper.StrongName.dll</HintPath>
40-
</Reference>
41-
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42-
<HintPath>..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
43-
</Reference>
44-
<Reference Include="Microsoft.Data.Edm, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45-
<HintPath>..\..\packages\Microsoft.Data.Edm.5.7.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
46-
</Reference>
47-
<Reference Include="Microsoft.Data.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\packages\Microsoft.Data.OData.5.7.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Microsoft.Data.Services.Client, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51-
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.7.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
52-
</Reference>
53-
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
54-
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
55-
</Reference>
56-
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
57-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
58-
</Reference>
59-
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
60-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
61-
</Reference>
62-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
63-
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
64-
</Reference>
65-
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
67-
</Reference>
68-
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69-
<HintPath>..\..\packages\WindowsAzure.Storage.7.1.2\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
70-
</Reference>
71-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
72-
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
73-
</Reference>
7439
<Reference Include="System" />
7540
<Reference Include="System.ComponentModel.Composition" />
7641
<Reference Include="System.Core" />
7742
<Reference Include="System.Net" />
7843
<Reference Include="System.Net.Http" />
79-
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
80-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
81-
</Reference>
82-
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
83-
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
84-
</Reference>
8544
<Reference Include="System.Net.Http.WebRequest" />
86-
<Reference Include="System.Spatial, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
87-
<HintPath>..\..\packages\System.Spatial.5.7.0\lib\net40\System.Spatial.dll</HintPath>
88-
</Reference>
8945
<Reference Include="System.Xml.Linq" />
9046
<Reference Include="System.Data.DataSetExtensions" />
9147
<Reference Include="Microsoft.CSharp" />
@@ -99,7 +55,6 @@
9955
</ItemGroup>
10056
<ItemGroup>
10157
<None Include="App.config" />
102-
<None Include="packages.config" />
10358
<None Include="Scripts\*" />
10459
<None Include="UpdateLicenseReports.nuspec" />
10560
</ItemGroup>
@@ -109,20 +64,23 @@
10964
<Name>NuGet.Jobs.Common</Name>
11065
</ProjectReference>
11166
</ItemGroup>
67+
<ItemGroup>
68+
<PackageReference Include="Dapper.StrongName">
69+
<Version>1.50.2</Version>
70+
</PackageReference>
71+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
72+
<Version>1.0.0</Version>
73+
</PackageReference>
74+
<PackageReference Include="Newtonsoft.Json">
75+
<Version>9.0.1</Version>
76+
</PackageReference>
77+
<PackageReference Include="Newtonsoft.Json.Schema">
78+
<Version>2.0.10</Version>
79+
</PackageReference>
80+
<PackageReference Include="NuGet.Services.Sql">
81+
<Version>2.25.0-master-30453</Version>
82+
</PackageReference>
83+
</ItemGroup>
11284
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
11385
<Import Project="..\..\build\sign.targets" Condition="Exists('..\..\build\sign.targets')" />
114-
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
115-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
116-
<PropertyGroup>
117-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
118-
</PropertyGroup>
119-
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
120-
</Target>
121-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
122-
Other similar extension points exist, see Microsoft.Common.targets.
123-
<Target Name="BeforeBuild">
124-
</Target>
125-
<Target Name="AfterBuild">
126-
</Target>
127-
-->
12886
</Project>

src/UpdateLicenseReports/packages.config

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

0 commit comments

Comments
 (0)