diff --git a/src/NuGet.Jobs.Common/Configuration/SupportRequestDbConfiguration.cs b/src/NuGet.Jobs.Common/Configuration/SupportRequestDbConfiguration.cs new file mode 100644 index 000000000..a2a7b4246 --- /dev/null +++ b/src/NuGet.Jobs.Common/Configuration/SupportRequestDbConfiguration.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace NuGet.Jobs.Configuration +{ + public class SupportRequestDbConfiguration : IDbConfiguration + { + public string ConnectionString { get; set; } + } +} diff --git a/src/NuGet.Jobs.Common/JsonConfigurationJob.cs b/src/NuGet.Jobs.Common/JsonConfigurationJob.cs index 02d79c085..948f188cb 100644 --- a/src/NuGet.Jobs.Common/JsonConfigurationJob.cs +++ b/src/NuGet.Jobs.Common/JsonConfigurationJob.cs @@ -26,6 +26,7 @@ public abstract class JsonConfigurationJob : JobBase private const string InitializationConfigurationSectionName = "Initialization"; private const string GalleryDbConfigurationSectionName = "GalleryDb"; private const string StatisticsDbConfigurationSectionName = "StatisticsDb"; + private const string SupportRequestDbConfigurationSectionName = "SupportRequestDb"; private const string ValidationDbConfigurationSectionName = "ValidationDb"; private const string ServiceBusConfigurationSectionName = "ServiceBus"; private const string ValidationStorageConfigurationSectionName = "ValidationStorage"; @@ -111,6 +112,7 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services, { services.Configure(configurationRoot.GetSection(GalleryDbConfigurationSectionName)); services.Configure(configurationRoot.GetSection(StatisticsDbConfigurationSectionName)); + services.Configure(configurationRoot.GetSection(SupportRequestDbConfigurationSectionName)); services.Configure(configurationRoot.GetSection(ValidationDbConfigurationSectionName)); services.Configure(configurationRoot.GetSection(ServiceBusConfigurationSectionName)); services.Configure(configurationRoot.GetSection(ValidationStorageConfigurationSectionName)); @@ -118,25 +120,20 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services, services.AddSingleton(new TelemetryClient()); services.AddTransient(); - services.AddScoped>(p => - { - return new DelegateSqlConnectionFactory( - CreateSqlConnectionAsync, - p.GetRequiredService>>()); - }); - - services.AddScoped>(p => - { - return new DelegateSqlConnectionFactory( - CreateSqlConnectionAsync, - p.GetRequiredService>>()); - }); + AddScopedSqlConnectionFactory(services); + AddScopedSqlConnectionFactory(services); + AddScopedSqlConnectionFactory(services); + AddScopedSqlConnectionFactory(services); + } - services.AddScoped>(p => + private void AddScopedSqlConnectionFactory(IServiceCollection services) + where TDbConfiguration : IDbConfiguration + { + services.AddScoped>(p => { - return new DelegateSqlConnectionFactory( - CreateSqlConnectionAsync, - p.GetRequiredService>>()); + return new DelegateSqlConnectionFactory( + CreateSqlConnectionAsync, + p.GetRequiredService>>()); }); } @@ -150,22 +147,19 @@ private void ConfigureLibraries(IServiceCollection services) protected virtual void RegisterDatabases(IServiceProvider serviceProvider) { - var galleryDb = serviceProvider.GetRequiredService>(); - if (!string.IsNullOrEmpty(galleryDb.Value?.ConnectionString)) - { - RegisterDatabase(serviceProvider); - } - - var statisticsDb = serviceProvider.GetRequiredService>(); - if (!string.IsNullOrEmpty(statisticsDb.Value?.ConnectionString)) - { - RegisterDatabase(serviceProvider); - } + RegisterDatabaseIfConfigured(serviceProvider); + RegisterDatabaseIfConfigured(serviceProvider); + RegisterDatabaseIfConfigured(serviceProvider); + RegisterDatabaseIfConfigured(serviceProvider); + } - var validationDb = serviceProvider.GetRequiredService>(); - if (!string.IsNullOrEmpty(validationDb.Value?.ConnectionString)) + private void RegisterDatabaseIfConfigured(IServiceProvider serviceProvider) + where TDbConfiguration : IDbConfiguration + { + var dbConfiguration = serviceProvider.GetRequiredService>(); + if (!string.IsNullOrEmpty(dbConfiguration.Value?.ConnectionString)) { - RegisterDatabase(serviceProvider); + RegisterDatabase(serviceProvider); } } diff --git a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj index 4450e2a24..f79ffb264 100644 --- a/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj +++ b/src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj @@ -48,6 +48,7 @@ + @@ -93,13 +94,13 @@ 2.27.0 - 2.27.0 + 2.28.0 2.27.0 - 2.27.0 + 2.28.0 4.3.3 diff --git a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj index c8eefd589..d5fb0c9d6 100644 --- a/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj +++ b/src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj @@ -137,9 +137,6 @@ 1.2.0 - - 2.27.0 - 2.27.0-master-35351 diff --git a/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs b/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs new file mode 100644 index 000000000..5d7d816d7 --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Configuration/InitializationConfiguration.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace NuGet.SupportRequests.Notifications +{ + public class InitializationConfiguration + { + /// + /// Obsolete: replace with IcM configuration + /// + public string PagerDutyAccountName { get; set; } + + /// + /// Obsolete: replace with IcM configuration + /// + public string PagerDutyApiKey { get; set; } + + /// + /// SMTP configuration. + /// + public string SmtpUri { get; set; } + + /// + /// Email address to which the weekly report is sent. + /// + public string TargetEmailAddress { get; set; } + } +} diff --git a/src/NuGet.SupportRequests.Notifications/Job.cs b/src/NuGet.SupportRequests.Notifications/Job.cs index 99de91ce9..b5fe49e11 100644 --- a/src/NuGet.SupportRequests.Notifications/Job.cs +++ b/src/NuGet.SupportRequests.Notifications/Job.cs @@ -1,36 +1,50 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Threading.Tasks; +using Autofac; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using NuGet.Jobs; +using NuGet.Jobs.Configuration; namespace NuGet.SupportRequests.Notifications { internal class Job - : JobBase + : JsonConfigurationJob { - private IServiceContainer _serviceContainer; - private IDictionary _jobArgsDictionary; + private InitializationConfiguration _configuration; + private string _taskName; public override void Init(IServiceContainer serviceContainer, IDictionary jobArgsDictionary) { - if (!jobArgsDictionary.ContainsKey(JobArgumentNames.ScheduledTask)) - { - throw new NotSupportedException("The required argument -Task is missing."); - } + base.Init(serviceContainer, jobArgsDictionary); - _serviceContainer = serviceContainer ?? throw new ArgumentNullException(nameof(serviceContainer)); - _jobArgsDictionary = jobArgsDictionary; + _taskName = jobArgsDictionary[JobArgumentNames.ScheduledTask]; + _configuration = _serviceProvider.GetRequiredService>().Value; } public override async Task Run() { - var scheduledTask = ScheduledTaskFactory.Create(_serviceContainer, _jobArgsDictionary, LoggerFactory); + var scheduledTask = ScheduledTaskFactory.Create( + _taskName, + _configuration, + OpenSqlConnectionAsync, + LoggerFactory); await scheduledTask.RunAsync(); } + + protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder) + { + } + + protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) + { + ConfigureInitializationSection(services, configurationRoot); + } } } \ No newline at end of file diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj index c506ac961..89eea823f 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.csproj @@ -44,6 +44,7 @@ + True True @@ -95,20 +96,17 @@ + + + - - 1.0.0 - 1.0.0 9.0.1 - - 2.27.0 - diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec index 04a564453..3c461cab3 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec @@ -14,5 +14,7 @@ + + \ No newline at end of file diff --git a/src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs b/src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs index 67586efb9..97f32ff6e 100644 --- a/src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs +++ b/src/NuGet.SupportRequests.Notifications/ScheduledTaskFactory.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.ComponentModel.Design; +using System.Data.SqlClient; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace NuGet.SupportRequests.Notifications @@ -12,11 +12,15 @@ internal class ScheduledTaskFactory { private const string _tasksNamespace = "NuGet.SupportRequests.Notifications.Tasks"; - public static IScheduledTask Create(IServiceContainer serviceContainer, IDictionary jobArgsDictionary, ILoggerFactory loggerFactory) + public static IScheduledTask Create( + string scheduledTaskName, + InitializationConfiguration configuration, + Func> openSupportRequestSqlConnectionAsync, + ILoggerFactory loggerFactory) { - if (jobArgsDictionary == null) + if (configuration == null) { - throw new ArgumentNullException(nameof(jobArgsDictionary)); + throw new ArgumentNullException(nameof(configuration)); } if (loggerFactory == null) @@ -24,16 +28,19 @@ public static IScheduledTask Create(IServiceContainer serviceContainer, IDiction throw new ArgumentNullException(nameof(loggerFactory)); } - var scheduledTaskName = jobArgsDictionary[JobArgumentNames.ScheduledTask]; - var scheduledTask = GetTaskOfType(scheduledTaskName, serviceContainer, jobArgsDictionary, loggerFactory); + var scheduledTask = GetTaskOfType( + scheduledTaskName, + configuration, + openSupportRequestSqlConnectionAsync, + loggerFactory); return scheduledTask; } private static IScheduledTask GetTaskOfType( string taskName, - IServiceContainer serviceContainer, - IDictionary jobArgsDictionary, + InitializationConfiguration configuration, + Func> openSupportRequestSqlConnectionAsync, ILoggerFactory loggerFactory) { if (string.IsNullOrEmpty(taskName)) @@ -51,7 +58,12 @@ private static IScheduledTask GetTaskOfType( IScheduledTask scheduledTask; if (scheduledTaskType != null && typeof(IScheduledTask).IsAssignableFrom(scheduledTaskType)) { - var args = new object[] { serviceContainer, jobArgsDictionary, loggerFactory }; + var args = new object[] { + configuration, + openSupportRequestSqlConnectionAsync, + loggerFactory + }; + scheduledTask = (IScheduledTask)Activator.CreateInstance(scheduledTaskType, args); } else diff --git a/src/NuGet.SupportRequests.Notifications/Scripts/OnCallDailyNotification.cmd b/src/NuGet.SupportRequests.Notifications/Scripts/OnCallDailyNotification.cmd index 1de25ed7c..3f35d10bf 100644 --- a/src/NuGet.SupportRequests.Notifications/Scripts/OnCallDailyNotification.cmd +++ b/src/NuGet.SupportRequests.Notifications/Scripts/OnCallDailyNotification.cmd @@ -7,16 +7,10 @@ echo "Starting job - NuGet - SupportRequests.Notifications.OnCallDailyNotificati title "NuGet - SupportRequests.Notifications.OnCallDailyNotification.cmd" start /w nuget.supportrequests.notifications.exe ^ - -Task "OnCallDailyNotification" ^ - -SourceDatabase "#{Jobs.supportrequests.notifications.SupportRequestsDatabase}" ^ - -PagerDutyAccountName "nuget" ^ - -PagerDutyApiKey "$$Prod-PagerDuty-ApiKey$$" ^ - -SmtpUri "#{Jobs.supportrequests.notifications.SmtpUri}" ^ - -VaultName "#{Deployment.Azure.KeyVault.VaultName}" ^ - -ClientId "#{Deployment.Azure.KeyVault.ClientId}" ^ - -CertificateThumbprint "#{Deployment.Azure.KeyVault.CertificateThumbprint}" ^ - -InstrumentationKey "#{Jobs.supportrequests.notifications.InstrumentationKey}" ^ - -verbose true ^ - -Once + -Task "OnCallDailyNotification" ^ + -Configuration "#{Jobs.supportrequests.notifications.Configuration}" ^ + -InstrumentationKey "#{Jobs.supportrequests.notifications.InstrumentationKey}" ^ + -verbose true ^ + -Once echo "Finished job - NuGet - SupportRequests.Notifications.OnCallDailyNotification.cmd" \ No newline at end of file diff --git a/src/NuGet.SupportRequests.Notifications/Scripts/WeeklySummaryNotification.cmd b/src/NuGet.SupportRequests.Notifications/Scripts/WeeklySummaryNotification.cmd index 49771cd2c..0a9b3a9cf 100644 --- a/src/NuGet.SupportRequests.Notifications/Scripts/WeeklySummaryNotification.cmd +++ b/src/NuGet.SupportRequests.Notifications/Scripts/WeeklySummaryNotification.cmd @@ -8,14 +8,7 @@ title "NuGet - SupportRequests.Notifications.WeeklySummaryNotification.cmd" start /w nuget.supportrequests.notifications.exe ^ -Task "WeeklySummaryNotification" ^ - -TargetEmailAddress "#{Jobs.supportrequests.notifications.weeklysummarynotification.TargetEmailAddress}" ^ - -SourceDatabase "#{Jobs.supportrequests.notifications.SupportRequestsDatabase}" ^ - -PagerDutyAccountName "nuget" ^ - -PagerDutyApiKey "$$Prod-PagerDuty-ApiKey$$" ^ - -SmtpUri "#{Jobs.supportrequests.notifications.SmtpUri}" ^ - -VaultName "#{Deployment.Azure.KeyVault.VaultName}" ^ - -ClientId "#{Deployment.Azure.KeyVault.ClientId}" ^ - -CertificateThumbprint "#{Deployment.Azure.KeyVault.CertificateThumbprint}" ^ + -Configuration "#{Jobs.supportrequests.notifications.Configuration}" ^ -InstrumentationKey "#{Jobs.supportrequests.notifications.InstrumentationKey}" ^ -verbose true ^ -Once diff --git a/src/NuGet.SupportRequests.Notifications/Settings/dev.json b/src/NuGet.SupportRequests.Notifications/Settings/dev.json new file mode 100644 index 000000000..a00d80563 --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Settings/dev.json @@ -0,0 +1,19 @@ +{ + "Initialization": { + "PagerDutyAccountName": "nuget", + "PagerDutyApiKey": "$$Dev-PagerDuty-ApiKey$$", + "SmtpUri": "#{Jobs.supportrequests.notifications.SmtpUri}", + "TargetEmailAddress": "#{Jobs.supportrequests.notifications.weeklysummarynotification.TargetEmailAddress}" + }, + + "SupportRequestDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.SupportRequestDatabaseAddress};Initial Catalog=nuget-dev-supportrequest;User ID=$$Dev-SupportRequestDBWriter-UserName$$;Password=$$Dev-SupportRequestDBWriter-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/NuGet.SupportRequests.Notifications/Settings/int.json b/src/NuGet.SupportRequests.Notifications/Settings/int.json new file mode 100644 index 000000000..f73fdae0d --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Settings/int.json @@ -0,0 +1,19 @@ +{ + "Initialization": { + "PagerDutyAccountName": "nuget", + "PagerDutyApiKey": "$$Int-PagerDuty-ApiKey$$", + "SmtpUri": "#{Jobs.supportrequests.notifications.SmtpUri}", + "TargetEmailAddress": "#{Jobs.supportrequests.notifications.weeklysummarynotification.TargetEmailAddress}" + }, + + "SupportRequestDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.SupportRequestDatabaseAddress};Initial Catalog=nuget-int-supportrequest;User ID=$$Int-SupportRequestDBWriter-UserName$$;Password=$$Int-SupportRequestDBWriter-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/NuGet.SupportRequests.Notifications/Settings/prod.json b/src/NuGet.SupportRequests.Notifications/Settings/prod.json new file mode 100644 index 000000000..40fcaa8b9 --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Settings/prod.json @@ -0,0 +1,19 @@ +{ + "Initialization": { + "PagerDutyAccountName": "nuget", + "PagerDutyApiKey": "$$Prod-PagerDuty-ApiKey$$", + "SmtpUri": "#{Jobs.supportrequests.notifications.SmtpUri}", + "TargetEmailAddress": "#{Jobs.supportrequests.notifications.weeklysummarynotification.TargetEmailAddress}" + }, + + "SupportRequestDb": { + "ConnectionString": "Data Source=tcp:#{Deployment.Azure.Sql.SupportRequestDatabaseAddress};Initial Catalog=nuget-prod-supportrequest;User ID=$$Prod-SupportRequestDBReadOnly-UserName$$;Password=$$Prod-SupportRequestDBReadOnly-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/NuGet.SupportRequests.Notifications/SupportRequestRepository.cs b/src/NuGet.SupportRequests.Notifications/SupportRequestRepository.cs index 1dcea245b..bb41d630c 100644 --- a/src/NuGet.SupportRequests.Notifications/SupportRequestRepository.cs +++ b/src/NuGet.SupportRequests.Notifications/SupportRequestRepository.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using NuGet.Services.Sql; using NuGet.SupportRequests.Notifications.Models; namespace NuGet.SupportRequests.Notifications @@ -20,29 +19,29 @@ internal class SupportRequestRepository private const string _parameterNamePagerDutyUsername = "pagerDutyUserName"; private readonly DateTime _defaultSqlDateTime = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc); private readonly ILogger _logger; - private readonly ISqlConnectionFactory _supportDbConnectionFactory; + private readonly Func> _openSupportRequestSqlConnectionAsync; public SupportRequestRepository( ILoggerFactory loggerFactory, - ISqlConnectionFactory supportDbConnectionFactory) + Func> openSupportRequestSqlConnectionAsync) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } - if (supportDbConnectionFactory == null) + if (openSupportRequestSqlConnectionAsync == null) { - throw new ArgumentNullException(nameof(supportDbConnectionFactory)); + throw new ArgumentNullException(nameof(openSupportRequestSqlConnectionAsync)); } _logger = loggerFactory.CreateLogger(); - _supportDbConnectionFactory = supportDbConnectionFactory; + _openSupportRequestSqlConnectionAsync = openSupportRequestSqlConnectionAsync; } internal async Task OpenConnectionAsync() { - var connection = await _supportDbConnectionFactory.CreateAsync(); + var connection = await _openSupportRequestSqlConnectionAsync(); connection.InfoMessage += OnSqlConnectionInfoMessage; return connection; diff --git a/src/NuGet.SupportRequests.Notifications/Tasks/OnCallDailyNotificationTask.cs b/src/NuGet.SupportRequests.Notifications/Tasks/OnCallDailyNotificationTask.cs index 35892f72d..d01b22b20 100644 --- a/src/NuGet.SupportRequests.Notifications/Tasks/OnCallDailyNotificationTask.cs +++ b/src/NuGet.SupportRequests.Notifications/Tasks/OnCallDailyNotificationTask.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; +using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,14 +23,14 @@ internal class OnCallDailyNotificationTask private readonly PagerDutyClient _pagerDutyClient; public OnCallDailyNotificationTask( - IServiceContainer serviceContainer, - IDictionary jobArgsDictionary, + InitializationConfiguration configuration, + Func> openSupportRequestSqlConnectionAsync, ILoggerFactory loggerFactory) - : base(serviceContainer, jobArgsDictionary, loggerFactory) + : base(configuration, openSupportRequestSqlConnectionAsync, loggerFactory) { var pagerDutyConfiguration = new PagerDutyConfiguration( - jobArgsDictionary[_argumentNamePagerDutyAccountName], - jobArgsDictionary[_argumentNamePagerDutyApiKey] + configuration.PagerDutyAccountName, + configuration.PagerDutyApiKey ); _pagerDutyClient = new PagerDutyClient(pagerDutyConfiguration); diff --git a/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs b/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs index 6976ed0bb..8f0d0312d 100644 --- a/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs +++ b/src/NuGet.SupportRequests.Notifications/Tasks/SupportRequestsNotificationScheduledTask.cs @@ -2,12 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; -using System.ComponentModel.Design; +using System.Data.SqlClient; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -using NuGet.Services.KeyVault; -using NuGet.Services.Sql; using NuGet.SupportRequests.Notifications.Notifications; using NuGet.SupportRequests.Notifications.Services; using NuGet.SupportRequests.Notifications.Templates; @@ -18,17 +15,19 @@ internal abstract class SupportRequestsNotificationScheduledTask : IScheduledTask where TNotification : INotification { + private InitializationConfiguration _configuration; + private readonly SupportRequestRepository _supportRequestRepository; private readonly MessagingService _messagingService; protected SupportRequestsNotificationScheduledTask( - IServiceContainer serviceContainer, - IDictionary jobArgsDictionary, + InitializationConfiguration configuration, + Func> openSupportRequestSqlConnectionAsync, ILoggerFactory loggerFactory) { - if (jobArgsDictionary == null) + if (configuration == null) { - throw new ArgumentNullException(nameof(jobArgsDictionary)); + throw new ArgumentNullException(nameof(configuration)); } if (loggerFactory == null) @@ -36,17 +35,13 @@ protected SupportRequestsNotificationScheduledTask( throw new ArgumentNullException(nameof(loggerFactory)); } - var smtpUri = jobArgsDictionary[JobArgumentNames.SmtpUri]; - _messagingService = new MessagingService(loggerFactory, smtpUri); - - var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector)); - var supportDbConnectionString = jobArgsDictionary[JobArgumentNames.SourceDatabase]; - var supportDbConnectionFactory = new AzureSqlConnectionFactory(supportDbConnectionString, secretInjector); + _messagingService = new MessagingService(loggerFactory, configuration.SmtpUri); - _supportRequestRepository = new SupportRequestRepository(loggerFactory, supportDbConnectionFactory); + _supportRequestRepository = new SupportRequestRepository(loggerFactory, openSupportRequestSqlConnectionAsync); } protected abstract Task BuildNotification(SupportRequestRepository supportRequestRepository, DateTime referenceTime); + protected abstract string BuildNotificationBody(string template, TNotification notification); public async Task RunAsync() diff --git a/src/NuGet.SupportRequests.Notifications/Tasks/WeeklySummaryNotificationTask.cs b/src/NuGet.SupportRequests.Notifications/Tasks/WeeklySummaryNotificationTask.cs index 71a0f9ccf..62d25cab3 100644 --- a/src/NuGet.SupportRequests.Notifications/Tasks/WeeklySummaryNotificationTask.cs +++ b/src/NuGet.SupportRequests.Notifications/Tasks/WeeklySummaryNotificationTask.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; +using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,12 +22,12 @@ internal class WeeklySummaryNotificationTask private readonly string _targetEmailAddress; public WeeklySummaryNotificationTask( - IServiceContainer serviceContainer, - IDictionary jobArgsDictionary, + InitializationConfiguration configuration, + Func> openSupportRequestSqlConnectionAsync, ILoggerFactory loggerFactory) - : base(serviceContainer, jobArgsDictionary, loggerFactory) + : base(configuration, openSupportRequestSqlConnectionAsync, loggerFactory) { - _targetEmailAddress = jobArgsDictionary[_argumentNameTargetEmailAddress]; + _targetEmailAddress = configuration.TargetEmailAddress; } protected override async Task BuildNotification( diff --git a/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj b/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj index 66606dd9c..f79edf412 100644 --- a/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj +++ b/src/Stats.RefreshClientDimension/Stats.RefreshClientDimension.csproj @@ -84,7 +84,7 @@ 9.0.1 - 2.27.0 + 2.28.0 1.2.0 diff --git a/src/Validation.Common.Job/Validation.Common.Job.csproj b/src/Validation.Common.Job/Validation.Common.Job.csproj index 600e121a0..2050373b1 100644 --- a/src/Validation.Common.Job/Validation.Common.Job.csproj +++ b/src/Validation.Common.Job/Validation.Common.Job.csproj @@ -102,9 +102,6 @@ 2.28.0 - - 2.28.0 - 2.28.0 diff --git a/src/Validation.Common/Validation.Common.csproj b/src/Validation.Common/Validation.Common.csproj index 75cc170e2..09e962b08 100644 --- a/src/Validation.Common/Validation.Common.csproj +++ b/src/Validation.Common/Validation.Common.csproj @@ -107,9 +107,6 @@ 4.1.0 - - 2.27.0 - 2.27.0 diff --git a/src/Validation.PackageSigning.ProcessSignature/Validation.PackageSigning.ProcessSignature.csproj b/src/Validation.PackageSigning.ProcessSignature/Validation.PackageSigning.ProcessSignature.csproj index 3d331e9f9..1ae9d197a 100644 --- a/src/Validation.PackageSigning.ProcessSignature/Validation.PackageSigning.ProcessSignature.csproj +++ b/src/Validation.PackageSigning.ProcessSignature/Validation.PackageSigning.ProcessSignature.csproj @@ -85,11 +85,6 @@ Validation.PackageSigning.Core - - - 2.27.0 - - ..\..\build diff --git a/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj b/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj index 68cf4d3a2..8331c5a89 100644 --- a/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj +++ b/tests/NuGet.Jobs.Common.Tests/NuGet.Jobs.Common.Tests.csproj @@ -37,7 +37,6 @@ - @@ -48,6 +47,9 @@ 4.7.145 + + 4.3.3 + 2.3.1