diff --git a/src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs b/src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs index dc0d07ca5..8b0e91721 100644 --- a/src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs +++ b/src/Gallery.Maintenance/DeleteExpiredVerificationKeysTask.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Gallery.Maintenance.Models; using Microsoft.Extensions.Logging; +using NuGet.Jobs.Configuration; namespace Gallery.Maintenance { @@ -37,7 +38,7 @@ public override async Task RunAsync(Job job) { IEnumerable expiredKeys; - using (var connection = await job.GalleryDatabase.CreateAsync()) + using (var connection = await job.OpenSqlConnectionAsync()) { expiredKeys = await connection.QueryWithRetryAsync( SelectQuery, @@ -59,7 +60,7 @@ public override async Task RunAsync(Job job) if (expectedRowCount > 0) { - using (var connection = await job.GalleryDatabase.CreateAsync()) + using (var connection = await job.OpenSqlConnectionAsync()) { using (var transaction = connection.BeginTransaction()) { diff --git a/src/Gallery.Maintenance/Gallery.Maintenance.csproj b/src/Gallery.Maintenance/Gallery.Maintenance.csproj index 62fd453c0..8f1c347cb 100644 --- a/src/Gallery.Maintenance/Gallery.Maintenance.csproj +++ b/src/Gallery.Maintenance/Gallery.Maintenance.csproj @@ -53,6 +53,9 @@ Designer + + + @@ -67,9 +70,6 @@ 9.0.1 - - 2.27.0 - 4.3.3 diff --git a/src/Gallery.Maintenance/Gallery.Maintenance.nuspec b/src/Gallery.Maintenance/Gallery.Maintenance.nuspec index 6440c9435..f494b5e85 100644 --- a/src/Gallery.Maintenance/Gallery.Maintenance.nuspec +++ b/src/Gallery.Maintenance/Gallery.Maintenance.nuspec @@ -18,5 +18,7 @@ + + \ No newline at end of file diff --git a/src/Gallery.Maintenance/Job.cs b/src/Gallery.Maintenance/Job.cs index 488a49b92..cb2edb77a 100644 --- a/src/Gallery.Maintenance/Job.cs +++ b/src/Gallery.Maintenance/Job.cs @@ -3,33 +3,21 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; -using System.Data; using System.Linq; using System.Threading.Tasks; +using Autofac; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NuGet.Jobs; -using NuGet.Services.KeyVault; -using NuGet.Services.Sql; namespace Gallery.Maintenance { /// /// Runs all s against the Gallery database. /// - public class Job : JobBase + public class Job : JsonConfigurationJob { - - public ISqlConnectionFactory GalleryDatabase { get; private set; } - - public override void Init(IServiceContainer serviceContainer, IDictionary jobArgsDictionary) - { - var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector)); - var databaseConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.GalleryDatabase); - - GalleryDatabase = new AzureSqlConnectionFactory(databaseConnectionString, secretInjector); - } - public override async Task Run() { var failedTasks = new List(); @@ -88,5 +76,13 @@ public ILogger CreateTypedLogger(Type type) .MakeGenericMethod(type) .Invoke(null, new object[] { LoggerFactory }) as ILogger; } + + protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder) + { + } + + protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) + { + } } } diff --git a/src/Gallery.Maintenance/Scripts/Gallery.Maintenance.cmd b/src/Gallery.Maintenance/Scripts/Gallery.Maintenance.cmd index 2f35679a1..8bea3c4e0 100644 --- a/src/Gallery.Maintenance/Scripts/Gallery.Maintenance.cmd +++ b/src/Gallery.Maintenance/Scripts/Gallery.Maintenance.cmd @@ -7,7 +7,7 @@ cd bin title #{Jobs.Gallery.Maintenance.Title} - start /w Gallery.Maintenance.exe -VaultName "#{Deployment.Azure.KeyVault.VaultName}" -ClientId "#{Deployment.Azure.KeyVault.ClientId}" -CertificateThumbprint "#{Deployment.Azure.KeyVault.CertificateThumbprint}" -GalleryDatabase "#{Jobs.Gallery.Maintenance.GalleryDatabase}" -InstrumentationKey "#{Jobs.Gallery.Maintenance.InstrumentationKey}" -verbose true -Interval #{Jobs.Gallery.Maintenance.Interval} + start /w Gallery.Maintenance.exe -Configuration "#{Jobs.gallery.maintenance.Configuration}" -InstrumentationKey "#{Jobs.gallery.maintenance.InstrumentationKey}" -Interval #{Jobs.gallery.maintenance.Interval} echo "Finished #{Jobs.Gallery.Maintenance.Title}" diff --git a/src/Gallery.Maintenance/Settings/dev.json b/src/Gallery.Maintenance/Settings/dev.json new file mode 100644 index 000000000..0f11c6317 --- /dev/null +++ b/src/Gallery.Maintenance/Settings/dev.json @@ -0,0 +1,12 @@ +{ + "GalleryDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=nuget-dev-0-v2gallery;User ID=$$Dev-GalleryDBWriter-UserName$$;Password=$$Dev-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" + }, + + "KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}", + "KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}", + "KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}", + "KeyVault_ValidateCertificate": true, + "KeyVault_StoreName": "My", + "KeyVault_StoreLocation": "LocalMachine" +} \ No newline at end of file diff --git a/src/Gallery.Maintenance/Settings/int.json b/src/Gallery.Maintenance/Settings/int.json new file mode 100644 index 000000000..70bb344e5 --- /dev/null +++ b/src/Gallery.Maintenance/Settings/int.json @@ -0,0 +1,12 @@ +{ + "GalleryDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=nuget-int-0-v2gallery;User ID=$$Int-GalleryDBWriter-UserName$$;Password=$$Int-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" + }, + + "KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}", + "KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}", + "KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}", + "KeyVault_ValidateCertificate": true, + "KeyVault_StoreName": "My", + "KeyVault_StoreLocation": "LocalMachine" +} \ No newline at end of file diff --git a/src/Gallery.Maintenance/Settings/prod.json b/src/Gallery.Maintenance/Settings/prod.json new file mode 100644 index 000000000..bdd2203e2 --- /dev/null +++ b/src/Gallery.Maintenance/Settings/prod.json @@ -0,0 +1,12 @@ +{ + "GalleryDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.GalleryDatabaseAddress};Initial Catalog=NuGetGallery;User ID=$$Prod-GalleryDBWriter-UserName$$;Password=$$Prod-GalleryDBWriter-Password$$;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" + }, + + "KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}", + "KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}", + "KeyVault_CertificateThumbprint": "#{Deployment.Azure.KeyVault.CertificateThumbprint}", + "KeyVault_ValidateCertificate": true, + "KeyVault_StoreName": "My", + "KeyVault_StoreLocation": "LocalMachine" +} \ No newline at end of file