This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from NuGet/dev
[ReleasePrep][2018.11.06]RI of dev into master
- Loading branch information
Showing
100 changed files
with
3,216 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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.Net.Http; | ||
using System.Security.Cryptography; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.WindowsAzure.Storage; | ||
using NuGet.Services.Metadata.Catalog.Persistence; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// Adds the Content MD5 property to package blobs that are missing it. | ||
/// </summary> | ||
public class FixPackageHashHandler : IPackagesContainerHandler | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly ITelemetryService _telemetryService; | ||
private readonly ILogger<FixPackageHashHandler> _logger; | ||
|
||
public FixPackageHashHandler( | ||
HttpClient httpClient, | ||
ITelemetryService telemetryService, | ||
ILogger<FixPackageHashHandler> logger) | ||
{ | ||
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); | ||
_telemetryService = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public async Task ProcessPackageAsync(CatalogIndexEntry packageEntry, ICloudBlockBlob blob) | ||
{ | ||
await blob.FetchAttributesAsync(CancellationToken.None); | ||
|
||
// Skip the package if it has a Content MD5 hash | ||
if (blob.ContentMD5 != null) | ||
{ | ||
_telemetryService.TrackPackageAlreadyHasHash(packageEntry.Id, packageEntry.Version); | ||
return; | ||
} | ||
|
||
// Download the blob and calculate its hash. We use HttpClient to download blobs as Azure Blob Sotrage SDK | ||
// occassionally hangs. See: https://github.com/Azure/azure-storage-net/issues/470 | ||
string hash; | ||
using (var hashAlgorithm = MD5.Create()) | ||
using (var packageStream = await _httpClient.GetStreamAsync(blob.Uri)) | ||
{ | ||
var hashBytes = hashAlgorithm.ComputeHash(packageStream); | ||
|
||
hash = Convert.ToBase64String(hashBytes); | ||
} | ||
|
||
blob.ContentMD5 = hash; | ||
|
||
var condition = AccessCondition.GenerateIfMatchCondition(blob.ETag); | ||
await blob.SetPropertiesAsync( | ||
condition, | ||
options: null, | ||
operationContext: null); | ||
|
||
_telemetryService.TrackPackageHashFixed(packageEntry.Id, packageEntry.Version); | ||
|
||
_logger.LogWarning( | ||
"Updated package {PackageId} {PackageVersion}, set hash to '{Hash}' using ETag {ETag}", | ||
packageEntry.Id, | ||
packageEntry.Version, | ||
hash, | ||
blob.ETag); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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.Threading.Tasks; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// A processor that runs on entries found on a catalog page. | ||
/// See: https://docs.microsoft.com/en-us/nuget/api/catalog-resource#catalog-page | ||
/// </summary> | ||
public interface ICatalogIndexProcessor | ||
{ | ||
/// <summary> | ||
/// Process a single entry from a catalog page. | ||
/// </summary> | ||
/// <param name="catalogEntry">The catalog index entry that should be processed.</param> | ||
/// <returns>A task that completes once the entry has been processed.</returns> | ||
Task ProcessCatalogIndexEntryAsync(CatalogIndexEntry catalogEntry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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.Threading.Tasks; | ||
using NuGet.Services.Metadata.Catalog.Persistence; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// A handler that is run on packages in the packages container. | ||
/// </summary> | ||
public interface IPackagesContainerHandler | ||
{ | ||
/// <summary> | ||
/// Handle a package in the packages container. | ||
/// </summary> | ||
/// <param name="packageEntry">The package's catalog index entry.</param> | ||
/// <param name="blob">The package's blob in the packages container.</param> | ||
/// <returns>A task that completes once the package has been handled.</returns> | ||
Task ProcessPackageAsync(CatalogIndexEntry packageEntry, ICloudBlockBlob blob); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.