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

Commit a8fc313

Browse files
author
Scott Bommarito
authored
Merge pull request #366 from NuGet/dev
[ReleasePrep][2018.03.09]RI of dev into master
2 parents 5a85bee + 55a05b9 commit a8fc313

18 files changed

Lines changed: 698 additions & 142 deletions

src/Gallery.CredentialExpiration/Strings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Gallery.CredentialExpiration/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ WHERE u.[EmailAllowed] = 1
151151
AND u.[EmailAddress] <> ''
152152
AND cr.[Expires] <= DATEADD(day,@DaysBeforeExpiration,GETUTCDATE())
153153
AND cr.[Expires] > DATEADD(day,-1 * @DaysBeforeExpiration,GETUTCDATE())
154-
AND (cr.[Type] = 'apikey.v1' or cr.[Type] = 'apikey.v2')
154+
AND (cr.[Type] = 'apikey.v3' or cr.[Type] = 'apikey.v4')
155155
ORDER BY u.[Username]</value>
156156
</data>
157157
<data name="ExpiredEmailSubject" xml:space="preserve">

src/NuGet.Services.Validation.Orchestrator/Configuration/SmtpConfiguration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ namespace NuGet.Services.Validation.Orchestrator
55
{
66
public class SmtpConfiguration
77
{
8-
public string SmtpHost { get; set; }
9-
public int SmtpPort { get; set; }
10-
public bool EnableSsl { get; set; }
11-
public string Username { get; set; }
12-
public string Password { get; set; }
8+
public string SmtpUri { get; set; }
139
}
1410
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 NuGetGallery;
7+
8+
namespace NuGet.Services.Validation.Orchestrator
9+
{
10+
public interface IValidationPackageFileService : ICorePackageFileService
11+
{
12+
/// <summary>
13+
/// Copy a package from the validation container to a location specific for the validation set. This allows the
14+
/// validation set to have its own copy of the package to mutate (via <see cref="IProcessor"/>) and validate.
15+
/// </summary>
16+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
17+
Task CopyValidationPackageForValidationSetAsync(PackageValidationSet validationSet);
18+
19+
/// <summary>
20+
/// Copy a package from the packages container to a location specific for the validation set. This allows the
21+
/// validation set to have its own copy of the package to mutate (via <see cref="IProcessor"/>) and validate.
22+
/// </summary>
23+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
24+
Task CopyPackageFileForValidationSetAsync(PackageValidationSet validationSet);
25+
26+
/// <summary>
27+
/// Copy a package from a location specific for the validation set to the packages container.
28+
/// </summary>
29+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
30+
Task CopyValidationSetPackageToPackageFileAsync(PackageValidationSet validationSet);
31+
32+
/// <summary>
33+
/// Copy a package from the validation container to the packages container.
34+
/// </summary>
35+
/// <param name="id">The package ID.</param>
36+
/// <param name="normalizedVersion">The normalized package version.</param>
37+
Task CopyValidationPackageToPackageFileAsync(string id, string normalizedVersion);
38+
39+
/// <summary>
40+
/// Delete a package from a location specific for the validation set.
41+
/// </summary>
42+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
43+
Task DeletePackageForValidationSetAsync(PackageValidationSet validationSet);
44+
45+
/// <summary>
46+
/// Generates the URI for the specified validating package, which can be used to download it.
47+
/// </summary>
48+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
49+
/// <param name="endOfAccess">The timestamp that limits the URI usage period.</param>
50+
/// <returns>Time limited (if implementation supports) URI for the package.</returns>
51+
Task<Uri> GetPackageForValidationSetReadUriAsync(PackageValidationSet validationSet, DateTimeOffset endOfAccess);
52+
53+
/// <summary>
54+
/// Checks whether the validation set's package file exists.
55+
/// </summary>
56+
/// <param name="validationSet">The validation set, containing validation set and package identifiers.</param>
57+
/// <returns>True if file exists, false otherwise</returns>
58+
Task<bool> DoesValidationSetPackageExistAsync(PackageValidationSet validationSet);
59+
}
60+
}

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,21 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
190190
{
191191
var smtpConfigurationAccessor = serviceProvider.GetRequiredService<IOptionsSnapshot<SmtpConfiguration>>();
192192
var smtpConfiguration = smtpConfigurationAccessor.Value;
193+
if (string.IsNullOrWhiteSpace(smtpConfiguration.SmtpUri))
194+
{
195+
return new MailSenderConfiguration();
196+
}
197+
var smtpUri = new SmtpUri(new Uri(smtpConfiguration.SmtpUri));
193198
return new MailSenderConfiguration
194199
{
195200
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
196-
Host = smtpConfiguration.SmtpHost,
197-
Port = smtpConfiguration.SmtpPort,
198-
EnableSsl = smtpConfiguration.EnableSsl,
201+
Host = smtpUri.Host,
202+
Port = smtpUri.Port,
203+
EnableSsl = smtpUri.Secure,
199204
UseDefaultCredentials = false,
200-
Credentials = new NetworkCredential(smtpConfiguration.Username, smtpConfiguration.Password)
205+
Credentials = new NetworkCredential(
206+
smtpUri.UserName,
207+
smtpUri.Password)
201208
};
202209
});
203210
services.AddTransient<IMailSender>(serviceProvider =>
@@ -280,21 +287,27 @@ private static IServiceProvider CreateProvider(IServiceCollection services)
280287
parameterKey: ValidationStorageBindingKey);
281288

282289
containerBuilder
283-
.RegisterKeyedTypeWithKeyedParameter<NuGetGallery.ICorePackageFileService, NuGetGallery.CorePackageFileService, NuGetGallery.ICoreFileStorageService>(
290+
.RegisterKeyedTypeWithKeyedParameter<IValidationPackageFileService, ValidationPackageFileService, NuGetGallery.ICoreFileStorageService>(
284291
typeKey: ValidationStorageBindingKey,
285292
parameterKey: ValidationStorageBindingKey);
286293

287294
containerBuilder
288295
.RegisterTypeWithKeyedParameter<
289296
IValidationOutcomeProcessor,
290297
ValidationOutcomeProcessor,
291-
NuGetGallery.ICorePackageFileService>(ValidationStorageBindingKey);
298+
IValidationPackageFileService>(ValidationStorageBindingKey);
299+
300+
containerBuilder
301+
.RegisterTypeWithKeyedParameter<
302+
IValidationSetProvider,
303+
ValidationSetProvider,
304+
IValidationPackageFileService>(ValidationStorageBindingKey);
292305

293306
containerBuilder
294307
.RegisterTypeWithKeyedParameter<
295308
IValidationSetProcessor,
296309
ValidationSetProcessor,
297-
NuGetGallery.ICorePackageFileService>(ValidationStorageBindingKey);
310+
IValidationPackageFileService>(ValidationStorageBindingKey);
298311

299312
containerBuilder
300313
.RegisterType<ScopedMessageHandler<PackageValidationMessageData>>()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<Compile Include="Error.cs" />
5454
<Compile Include="IMessageService.cs" />
5555
<Compile Include="IValidationOutcomeProcessor.cs" />
56+
<Compile Include="IValidationPackageFileService.cs" />
5657
<Compile Include="IValidationSetProcessor.cs" />
5758
<Compile Include="IValidationSetProvider.cs" />
5859
<Compile Include="IValidationStorageService.cs" />
@@ -79,6 +80,7 @@
7980
<Compile Include="Configuration\ValidationConfiguration.cs" />
8081
<Compile Include="Configuration\ValidationConfigurationItem.cs" />
8182
<Compile Include="ValidationFailureBehavior.cs" />
83+
<Compile Include="ValidationPackageFileService.cs" />
8284
<Compile Include="Vcs\IPackageCriteria.cs" />
8385
<Compile Include="Vcs\IPackageCriteriaEvaluator.cs" />
8486
<Compile Include="Vcs\PackageCriteriaEvaluator.cs" />

src/NuGet.Services.Validation.Orchestrator/PackageCertificates/PackageCertificatesValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ private Task<PackageSignature> FindSignatureAsync(IValidationRequest request)
226226
{
227227
return _validationContext
228228
.PackageSignatures
229-
.Include(s => s.TrustedTimestamps)
230229
.Include(s => s.EndCertificate)
230+
.Include(s => s.TrustedTimestamps.Select(t => t.EndCertificate))
231231
.SingleAsync(s => s.PackageKey == request.PackageKey);
232232
}
233233

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

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace NuGet.Services.Validation.Orchestrator
1515
public class ValidationOutcomeProcessor : IValidationOutcomeProcessor
1616
{
1717
private readonly ICorePackageService _galleryPackageService;
18-
private readonly ICorePackageFileService _packageFileService;
18+
private readonly IValidationPackageFileService _packageFileService;
1919
private readonly IPackageValidationEnqueuer _validationEnqueuer;
2020
private readonly ValidationConfiguration _validationConfiguration;
2121
private readonly IMessageService _messageService;
@@ -24,7 +24,7 @@ public class ValidationOutcomeProcessor : IValidationOutcomeProcessor
2424

2525
public ValidationOutcomeProcessor(
2626
ICorePackageService galleryPackageService,
27-
ICorePackageFileService packageFileService,
27+
IValidationPackageFileService packageFileService,
2828
IPackageValidationEnqueuer validationEnqueuer,
2929
IOptionsSnapshot<ValidationConfiguration> validationConfigurationAccessor,
3030
IMessageService messageService,
@@ -106,6 +106,8 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
106106
validationSet.ValidationTrackingId);
107107
}
108108

109+
await _packageFileService.DeletePackageForValidationSetAsync(validationSet);
110+
109111
TrackTotalValidationDuration(validationSet, isSuccess: false);
110112
}
111113
else if (AllValidationsSucceeded(validationSet, GetValidationConfigurationItem))
@@ -114,6 +116,7 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
114116
package.PackageRegistration.Id,
115117
package.NormalizedVersion,
116118
validationSet.ValidationTrackingId);
119+
117120
if (package.PackageStatusKey != PackageStatus.Available)
118121
{
119122
await MoveFileToPublicStorageAndMarkPackageAsAvailable(validationSet, package);
@@ -139,6 +142,9 @@ ValidationConfigurationItem GetValidationConfigurationItem(string validationName
139142
TrackMissingNupkgForAvailablePackage(validationSet);
140143
}
141144
}
145+
146+
await _packageFileService.DeletePackageForValidationSetAsync(validationSet);
147+
142148
_logger.LogInformation("Done processing {PackageId} {PackageVersion} {ValidationSetId}",
143149
package.PackageRegistration.Id,
144150
package.NormalizedVersion,
@@ -176,23 +182,27 @@ private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValid
176182
package.PackageRegistration.Id,
177183
package.NormalizedVersion,
178184
validationSet.ValidationTrackingId);
179-
var packageStream = await _packageFileService.DownloadValidationPackageFileAsync(package);
180185

181-
try
186+
if (await _packageFileService.DoesValidationSetPackageExistAsync(validationSet))
182187
{
183-
await _packageFileService.SavePackageFileAsync(package, packageStream);
188+
await CopyAsync(
189+
validationSet,
190+
package,
191+
x => _packageFileService.CopyValidationSetPackageToPackageFileAsync(x));
184192
}
185-
catch (InvalidOperationException)
193+
else
186194
{
187-
// The package already exists in the packages container. This can happen if the DB commit below fails
188-
// and this flow is retried. We assume that the package content has not changed. Today there is no way
189-
// for the content to change. Hard deletes (the one way a package ID and version can get different
190-
// content) delete from both the packages and validating container so this can't be a mismatch.
191195
_logger.LogInformation(
192-
"Package already exists in packages container for {PackageId} {PackageVersion}, validation set {ValidationSetId}",
196+
"The package specific to the validation set does not exist. Falling back to the validation " +
197+
"container for package {PackageId} {PackageVersion}, validation set {ValidationSetId}",
193198
package.PackageRegistration.Id,
194199
package.NormalizedVersion,
195200
validationSet.ValidationTrackingId);
201+
202+
await CopyAsync(
203+
validationSet,
204+
package,
205+
x => _packageFileService.CopyValidationPackageToPackageFileAsync(x.PackageId, x.PackageNormalizedVersion));
196206
}
197207

198208
_logger.LogInformation("Marking package {PackageId} {PackageVersion}, validation set {ValidationSetId} as {PackageStatus} in DB",
@@ -229,6 +239,26 @@ private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValid
229239
await _packageFileService.DeleteValidationPackageFileAsync(package.PackageRegistration.Id, package.Version);
230240
}
231241

242+
private async Task CopyAsync(PackageValidationSet validationSet, Package package, Func<PackageValidationSet, Task> copyAsync)
243+
{
244+
try
245+
{
246+
await copyAsync(validationSet);
247+
}
248+
catch (InvalidOperationException)
249+
{
250+
// The package already exists in the packages container. This can happen if the DB commit below fails
251+
// and this flow is retried. We assume that the package content has not changed. Today there is no way
252+
// for the content to change. Hard deletes (the one way a package ID and version can get different
253+
// content) delete from both the packages and validating container so this can't be a mismatch.
254+
_logger.LogInformation(
255+
"Package already exists in packages container for {PackageId} {PackageVersion}, validation set {ValidationSetId}",
256+
package.PackageRegistration.Id,
257+
package.NormalizedVersion,
258+
validationSet.ValidationTrackingId);
259+
}
260+
}
261+
232262
private bool AllValidationsSucceeded(
233263
PackageValidationSet packageValidationSet,
234264
Func<string, ValidationConfigurationItem> getValidationConfigurationItem)

0 commit comments

Comments
 (0)