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

Commit 20e109e

Browse files
committed
Add ProcessorPackageFileService to allow processors to store .nupkgs (#388)
Progress on NuGet/Engineering#1207
1 parent e01c553 commit 20e109e

25 files changed

Lines changed: 441 additions & 31 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
namespace NuGet.Jobs.Configuration
5+
{
6+
public class ValidationStorageConfiguration
7+
{
8+
public string ConnectionString { get; set; }
9+
}
10+
}

src/NuGet.Jobs.Common/NuGet.Jobs.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<Compile Include="Configuration\JobArgumentNames.cs" />
192192
<Compile Include="Configuration\ServiceBusConfiguration.cs" />
193193
<Compile Include="Configuration\ValidationDbConfiguration.cs" />
194+
<Compile Include="Configuration\ValidationStorageConfiguration.cs" />
194195
<Compile Include="Extensions\SqlConnectionStringBuilderExtensions.cs" />
195196
<Compile Include="Extensions\XElementExtensions.cs" />
196197
<Compile Include="SecretReader\ISecretReaderFactory.cs" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
</ItemGroup>
109109
<ItemGroup>
110110
<PackageReference Include="NuGet.Services.Validation.Issues">
111-
<Version>2.19.1</Version>
111+
<Version>2.22.0</Version>
112112
</PackageReference>
113113
</ItemGroup>
114114
<ItemGroup>

src/PackageHash/PackageHash.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<Version>1.1.2</Version>
8080
</PackageReference>
8181
<PackageReference Include="NuGet.Services.Cursor">
82-
<Version>2.17.0</Version>
82+
<Version>2.22.0</Version>
8383
</PackageReference>
8484
</ItemGroup>
8585
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/PackageHash/Settings/dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
},
1515

16-
"PackageDownloadTimeout": "10:00",
16+
"PackageDownloadTimeout": "00:10:00",
1717

1818
"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
1919
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",

src/PackageHash/Settings/int.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
},
1515

16-
"PackageDownloadTimeout": "10:00",
16+
"PackageDownloadTimeout": "00:10:00",
1717

1818
"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
1919
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",

src/PackageHash/Settings/prod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
},
1515

16-
"PackageDownloadTimeout": "10:00",
16+
"PackageDownloadTimeout": "00:10:00",
1717

1818
"KeyVault_VaultName": "#{Deployment.Azure.KeyVault.VaultName}",
1919
"KeyVault_ClientId": "#{Deployment.Azure.KeyVault.ClientId}",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.IO;
5+
6+
namespace NuGet.Jobs.Validation
7+
{
8+
public static class FileStreamUtility
9+
{
10+
public const int BufferSize = 8192;
11+
12+
public static FileStream GetTemporaryFile()
13+
{
14+
return new FileStream(
15+
Path.GetTempFileName(),
16+
FileMode.Create,
17+
FileAccess.ReadWrite,
18+
FileShare.None,
19+
BufferSize,
20+
FileOptions.DeleteOnClose | FileOptions.Asynchronous);
21+
}
22+
}
23+
}

src/Validation.Common.Job/JsonConfigurationJob.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Extensions.Logging;
1616
using Microsoft.Extensions.Options;
1717
using NuGet.Jobs.Configuration;
18+
using NuGet.Jobs.Validation.Storage;
1819
using NuGet.Services.Configuration;
1920
using NuGet.Services.KeyVault;
2021
using NuGet.Services.Logging;
@@ -107,13 +108,23 @@ private void ConfigureDefaultJobServices(IServiceCollection services, IConfigura
107108
services.Configure<GalleryDbConfiguration>(configurationRoot.GetSection(GalleryDbConfigurationSectionName));
108109
services.Configure<ValidationDbConfiguration>(configurationRoot.GetSection(ValidationDbConfigurationSectionName));
109110
services.Configure<ServiceBusConfiguration>(configurationRoot.GetSection(ServiceBusConfigurationSectionName));
111+
services.Configure<ValidationStorageConfiguration>(configurationRoot.GetSection(ServiceBusConfigurationSectionName));
110112

111113
services.AddSingleton(new TelemetryClient());
112114
services.AddTransient<ITelemetryClient, TelemetryClientWrapper>();
113115
services.AddTransient<ICommonTelemetryService, CommonTelemetryService>();
114116
services.AddTransient<IDiagnosticsService, LoggerDiagnosticsService>();
115117
services.AddTransient<IPackageDownloader, PackageDownloader>();
116118

119+
services.AddTransient<ICloudBlobClient>(c =>
120+
{
121+
var configurationAccessor = c.GetRequiredService<IOptionsSnapshot<ValidationStorageConfiguration>>();
122+
return new CloudBlobClientWrapper(
123+
configurationAccessor.Value.ConnectionString,
124+
readAccessGeoRedundant: false);
125+
});
126+
services.AddTransient<ICoreFileStorageService, CloudBlobCoreFileStorageService>();
127+
117128
services.AddScoped<IValidationEntitiesContext>(p =>
118129
{
119130
var config = p.GetRequiredService<IOptionsSnapshot<ValidationDbConfiguration>>().Value;

src/Validation.Common.Job/PackageDownloader.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace NuGet.Jobs.Validation
1414
{
1515
public class PackageDownloader : IPackageDownloader
1616
{
17-
private const int BufferSize = 8192;
18-
1917
private readonly HttpClient _httpClient;
2018
private readonly ICommonTelemetryService _telemetryService;
2119
private readonly ILogger<PackageDownloader> _logger;
@@ -56,15 +54,9 @@ public async Task<Stream> DownloadAsync(Uri packageUri, CancellationToken cancel
5654

5755
using (var networkStream = await response.Content.ReadAsStreamAsync())
5856
{
59-
packageStream = new FileStream(
60-
Path.GetTempFileName(),
61-
FileMode.Create,
62-
FileAccess.ReadWrite,
63-
FileShare.None,
64-
BufferSize,
65-
FileOptions.DeleteOnClose | FileOptions.Asynchronous);
66-
67-
await networkStream.CopyToAsync(packageStream, BufferSize, cancellationToken);
57+
packageStream = FileStreamUtility.GetTemporaryFile();
58+
59+
await networkStream.CopyToAsync(packageStream, FileStreamUtility.BufferSize, cancellationToken);
6860
}
6961
}
7062

0 commit comments

Comments
 (0)