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

Commit 6c6da90

Browse files
Add email service support for the symbols. (#560)
* Add message support for symbols.
1 parent cca50ac commit 6c6da90

18 files changed

Lines changed: 346 additions & 189 deletions

src/NuGet.Services.Validation.Orchestrator/Job.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ private static void ConfigureOrchestratorSymbolTypes(IServiceCollection services
597597
services.AddTransient<IValidationOutcomeProcessor<SymbolPackage>, ValidationOutcomeProcessor<SymbolPackage>>();
598598
services.AddTransient<IStatusProcessor<SymbolPackage>, EntityStatusProcessor<SymbolPackage>>();
599599
services.AddTransient<IValidationSetProvider<SymbolPackage>, ValidationSetProvider<SymbolPackage>>();
600-
services.AddTransient<IMessageService<SymbolPackage>, SymbolPackageMessageService>();
600+
services.AddTransient<IMessageService<SymbolPackage>, SymbolsPackageMessageService>();
601601
services.AddTransient<IBrokeredMessageSerializer<SymbolsValidatorMessage>, SymbolsValidatorMessageSerializer>();
602602
services.AddTransient<ISymbolsValidationEntitiesService, SymbolsValidationEntitiesService>();
603603
}

src/NuGet.Services.Validation.Orchestrator/MessageService.cs

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

src/NuGet.Services.Validation.Orchestrator/NuGet.Services.Validation.Orchestrator.csproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@
5151
<Compile Include="DiskMailSender.cs" />
5252
<Compile Include="Configuration\EmailConfiguration.cs" />
5353
<Compile Include="Error.cs" />
54-
<Compile Include="SymbolMessageService.cs" />
54+
<Compile Include="Services\MessageServiceConfiguration.cs" />
55+
<Compile Include="Services\SymbolsMessageService.cs" />
5556
<Compile Include="Symbols\SymbolScanOnlyConfiguration.cs" />
5657
<Compile Include="Symbols\SymbolCriteriaEvaluator.cs" />
5758
<Compile Include="Symbols\SymbolScanValidator.cs" />
5859
<Compile Include="PackageSigning\Scan\ScanValidator.cs" />
5960
<Compile Include="Services\IEntityService.cs" />
60-
<Compile Include="IMessageService.cs" />
61+
<Compile Include="Services\IMessageService.cs" />
6162
<Compile Include="IPackageStatusProcessor.cs" />
6263
<Compile Include="Services\SymbolEntityService.cs" />
6364
<Compile Include="Symbols\ISymbolsMessageEnqueuer.cs" />
@@ -74,7 +75,7 @@
7475
<Compile Include="IValidationSetProvider.cs" />
7576
<Compile Include="IValidationStorageService.cs" />
7677
<Compile Include="Job.cs" />
77-
<Compile Include="MessageService.cs" />
78+
<Compile Include="Services\PackageMessageService.cs" />
7879
<Compile Include="OrchestrationRunner.cs" />
7980
<Compile Include="Configuration\OrchestrationRunnerConfiguration.cs" />
8081
<Compile Include="Services\PackageEntityService.cs" />
@@ -137,9 +138,6 @@
137138
<PackageReference Include="NuGet.StrongName.AnglicanGeek.MarkdownMailer">
138139
<Version>1.2.0</Version>
139140
</PackageReference>
140-
<PackageReference Include="NuGet.Services.Validation.Issues">
141-
<Version>2.27.0-master-35351</Version>
142-
</PackageReference>
143141
</ItemGroup>
144142
<ItemGroup>
145143
<ProjectReference Include="..\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj">

src/NuGet.Services.Validation.Orchestrator/IMessageService.cs renamed to src/NuGet.Services.Validation.Orchestrator/Services/IMessageService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Threading.Tasks;
45
using NuGetGallery;
56

67
namespace NuGet.Services.Validation.Orchestrator
78
{
89
public interface IMessageService<T> where T : class, IEntity
910
{
10-
void SendPublishedMessage(T entity);
11-
void SendValidationFailedMessage(T entity, PackageValidationSet validationSet);
12-
void SendValidationTakingTooLongMessage(T entity);
11+
Task SendPublishedMessageAsync(T entity);
12+
Task SendValidationFailedMessageAsync(T entity, PackageValidationSet validationSet);
13+
Task SendValidationTakingTooLongMessageAsync(T entity);
1314
}
1415
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.Extensions.Options;
6+
7+
namespace NuGet.Services.Validation.Orchestrator
8+
{
9+
public class MessageServiceConfiguration
10+
{
11+
public EmailConfiguration EmailConfiguration { get; }
12+
13+
public MessageServiceConfiguration(IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor)
14+
{
15+
if (emailConfigurationAccessor == null)
16+
{
17+
throw new ArgumentNullException(nameof(emailConfigurationAccessor));
18+
}
19+
EmailConfiguration = emailConfigurationAccessor.Value ?? throw new ArgumentException("Value cannot be null", nameof(emailConfigurationAccessor));
20+
if (string.IsNullOrWhiteSpace(EmailConfiguration.PackageUrlTemplate))
21+
{
22+
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.PackageUrlTemplate)} cannot be empty", nameof(emailConfigurationAccessor));
23+
}
24+
if (string.IsNullOrWhiteSpace(EmailConfiguration.PackageSupportTemplate))
25+
{
26+
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.PackageSupportTemplate)} cannot be empty", nameof(emailConfigurationAccessor));
27+
}
28+
if (string.IsNullOrWhiteSpace(EmailConfiguration.EmailSettingsUrl))
29+
{
30+
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.EmailSettingsUrl)} cannot be empty", nameof(emailConfigurationAccessor));
31+
}
32+
if (!Uri.TryCreate(EmailConfiguration.EmailSettingsUrl, UriKind.Absolute, out Uri result))
33+
{
34+
throw new ArgumentException($"{nameof(emailConfigurationAccessor.Value)}.{nameof(EmailConfiguration.EmailSettingsUrl)} must be an absolute Url", nameof(emailConfigurationAccessor));
35+
}
36+
}
37+
38+
public string GalleryPackageUrl(string packageId, string packageNormalizedVersion) => string.Format(EmailConfiguration.PackageUrlTemplate, packageId, packageNormalizedVersion);
39+
public string PackageSupportUrl(string packageId, string packageNormalizedVersion) => string.Format(EmailConfiguration.PackageSupportTemplate, packageId, packageNormalizedVersion);
40+
}
41+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Options;
8+
using NuGetGallery;
9+
using NuGetGallery.Services;
10+
11+
namespace NuGet.Services.Validation.Orchestrator
12+
{
13+
public class PackageMessageService : IMessageService<Package>
14+
{
15+
private readonly ICoreMessageService _coreMessageService;
16+
private readonly ILogger<PackageMessageService> _logger;
17+
private readonly MessageServiceConfiguration _serviceConfiguration;
18+
19+
public PackageMessageService(
20+
ICoreMessageService coreMessageService,
21+
IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor,
22+
ILogger<PackageMessageService> logger)
23+
{
24+
_serviceConfiguration = new MessageServiceConfiguration(emailConfigurationAccessor);
25+
_coreMessageService = coreMessageService ?? throw new ArgumentNullException(nameof(coreMessageService));
26+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
27+
}
28+
29+
public async Task SendPublishedMessageAsync(Package package)
30+
{
31+
package = package ?? throw new ArgumentNullException(nameof(package));
32+
33+
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion);
34+
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion);
35+
36+
await _coreMessageService.SendPackageAddedNoticeAsync(package, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.EmailSettingsUrl);
37+
}
38+
39+
public async Task SendValidationFailedMessageAsync(Package package, PackageValidationSet validationSet)
40+
{
41+
package = package ?? throw new ArgumentNullException(nameof(package));
42+
validationSet = validationSet ?? throw new ArgumentNullException(nameof(validationSet));
43+
44+
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion);
45+
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion);
46+
47+
await _coreMessageService.SendPackageValidationFailedNoticeAsync(package, validationSet, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.AnnouncementsUrl, _serviceConfiguration.EmailConfiguration.TwitterUrl);
48+
}
49+
50+
public async Task SendValidationTakingTooLongMessageAsync(Package package)
51+
{
52+
package = package ?? throw new ArgumentNullException(nameof(package));
53+
54+
await _coreMessageService.SendValidationTakingTooLongNoticeAsync(package, _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion));
55+
}
56+
}
57+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Options;
8+
using NuGetGallery;
9+
using NuGetGallery.Services;
10+
11+
namespace NuGet.Services.Validation.Orchestrator
12+
{
13+
public class SymbolsPackageMessageService : IMessageService<SymbolPackage>
14+
{
15+
private readonly ICoreMessageService _coreMessageService;
16+
private readonly ILogger<SymbolsPackageMessageService> _logger;
17+
private readonly MessageServiceConfiguration _serviceConfiguration;
18+
19+
public SymbolsPackageMessageService(
20+
ICoreMessageService coreMessageService,
21+
IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor,
22+
ILogger<SymbolsPackageMessageService> logger)
23+
{
24+
_serviceConfiguration = new MessageServiceConfiguration(emailConfigurationAccessor);
25+
_coreMessageService = coreMessageService ?? throw new ArgumentNullException(nameof(coreMessageService));
26+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
27+
}
28+
29+
public async Task SendPublishedMessageAsync(SymbolPackage symbolPackage)
30+
{
31+
if (symbolPackage == null)
32+
{
33+
throw new ArgumentNullException(nameof(symbolPackage));
34+
}
35+
36+
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
37+
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
38+
39+
await _coreMessageService.SendSymbolPackageAddedNoticeAsync(symbolPackage, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.EmailSettingsUrl);
40+
}
41+
42+
public async Task SendValidationFailedMessageAsync(SymbolPackage symbolPackage, PackageValidationSet validationSet)
43+
{
44+
if (symbolPackage == null)
45+
{
46+
throw new ArgumentNullException(nameof(symbolPackage));
47+
}
48+
validationSet = validationSet ?? throw new ArgumentNullException(nameof(validationSet));
49+
50+
var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
51+
var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion);
52+
53+
await _coreMessageService.SendSymbolPackageValidationFailedNoticeAsync(symbolPackage, validationSet, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.AnnouncementsUrl, _serviceConfiguration.EmailConfiguration.TwitterUrl);
54+
}
55+
56+
public async Task SendValidationTakingTooLongMessageAsync(SymbolPackage symbolPackage)
57+
{
58+
if (symbolPackage == null)
59+
{
60+
throw new ArgumentNullException(nameof(symbolPackage));
61+
}
62+
63+
await _coreMessageService.SendValidationTakingTooLongNoticeAsync(symbolPackage, _serviceConfiguration.GalleryPackageUrl(symbolPackage.Id, symbolPackage.Package.NormalizedVersion));
64+
}
65+
}
66+
}

src/NuGet.Services.Validation.Orchestrator/SymbolMessageService.cs

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

0 commit comments

Comments
 (0)