Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Add RegistrationDeprecationValidator to verify deprecation changes ar…
Browse files Browse the repository at this point in the history
…e properly consumed (#554)
  • Loading branch information
Scott Bommarito authored Jun 14, 2019
1 parent accf846 commit 45f07fe
Show file tree
Hide file tree
Showing 71 changed files with 573 additions and 392 deletions.
3 changes: 2 additions & 1 deletion src/Catalog/Helpers/Db2CatalogProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public FeedPackageDetails ReadFeedPackageDetailsFromDataReader(DbDataReader data
normalizedPackageVersion,
hideLicenseReport ? null : dataReader[Db2CatalogProjectionColumnNames.LicenseNames]?.ToString(),
hideLicenseReport ? null : dataReader[Db2CatalogProjectionColumnNames.LicenseReportUrl]?.ToString(),
deprecationInfo);
deprecationInfo,
dataReader.GetBoolean(dataReader.GetOrdinal(Db2CatalogProjectionColumnNames.RequiresLicenseAcceptance)));
}

public PackageDeprecationItem ReadDeprecationInfoFromDataReader(DbDataReader dataReader)
Expand Down
1 change: 1 addition & 0 deletions src/Catalog/Helpers/Db2CatalogProjectionColumnNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public static class Db2CatalogProjectionColumnNames
public const string AlternatePackageVersion = "AlternatePackageVersion";
public const string DeprecationStatus = "DeprecationStatus";
public const string DeprecationMessage = "DeprecationMessage";
public const string RequiresLicenseAcceptance = "RequiresLicenseAcceptance";
}
}
100 changes: 0 additions & 100 deletions src/Catalog/Helpers/FeedHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// 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.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Linq;

namespace NuGet.Services.Metadata.Catalog.Helpers
{
Expand All @@ -23,101 +19,5 @@ public static HttpClient CreateHttpClient(Func<HttpMessageHandler> handlerFunc)
var handler = (handlerFunc != null) ? handlerFunc() : new WebRequestHandler { AllowPipelining = true };
return new HttpClient(handler);
}

/// <summary>
/// Builds a <see cref="Uri"/> for accessing the metadata of a specific package on the feed.
/// </summary>
public static Uri MakeUriForPackage(string source, string id, string version)
{
var uri = new Uri($"{source.Trim('/')}/Packages(Id='{HttpUtility.UrlEncode(id)}',Version='{HttpUtility.UrlEncode(version)}')");
return UriUtils.GetNonhijackableUri(uri);
}

/// <summary>
/// Asynchronously gets a <see cref="IList{FeedPackageDetails}"/> from the feed.
/// </summary>
/// <param name="client">An HTTP client.</param>
/// <param name="uri">The feed URI.</param>
/// <returns>A task that represents the asynchronous operation.
/// The task result (<see cref="Task{TResult}.Result" />) returns an
/// <see cref="IList{FeedPackageDetails}" />.</returns>
public static async Task<IList<FeedPackageDetails>> GetPackages(HttpClient client, Uri uri)
{
const string createdDateProperty = "Created";
const string lastEditedDateProperty = "LastEdited";
const string publishedDateProperty = "Published";
const string idProperty = "Id";
const string normalizedVersionProperty = "NormalizedVersion";
const string licenseNamesProperty = "LicenseNames";
const string licenseReportUrlProperty = "LicenseReportUrl";

var packages = new List<FeedPackageDetails>();

XElement feed;
try
{
using (var stream = await client.GetStreamAsync(uri))
{
feed = XElement.Load(stream);
}
}
catch (TaskCanceledException tce)
{
// If the HTTP request timed out, a TaskCanceledException will be thrown.
throw new HttpClientTimeoutException($"HttpClient request timed out in {nameof(FeedHelpers.GetPackages)}.", tce);
}

XNamespace atom = "http://www.w3.org/2005/Atom";
XNamespace dataservices = "http://schemas.microsoft.com/ado/2007/08/dataservices";
XNamespace metadata = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";

foreach (var entry in feed.Elements(atom + "entry"))
{
var content = new Uri(entry.Element(atom + "content").Attribute("src").Value);

var propertiesElement = entry.Element(metadata + "properties");

var packageIdElement = propertiesElement.Element(dataservices + idProperty);
var packageId = packageIdElement?.Value;
var packageNormalizedVersionElement = propertiesElement.Element(dataservices + normalizedVersionProperty);
var packageNormalizedVersion = packageNormalizedVersionElement?.Value;

var createdElement = propertiesElement.Element(dataservices + createdDateProperty);
var createdValue = createdElement?.Value;
var createdDate = string.IsNullOrEmpty(createdValue) ? DateTime.MinValue : DateTime.Parse(createdValue);

var lastEditedValue = propertiesElement.Element(dataservices + lastEditedDateProperty).Value;
var lastEditedDate = string.IsNullOrEmpty(lastEditedValue) ? DateTime.MinValue : DateTime.Parse(lastEditedValue);

var publishedValue = propertiesElement.Element(dataservices + publishedDateProperty).Value;
var publishedDate = string.IsNullOrEmpty(publishedValue) ? createdDate : DateTime.Parse(publishedValue);

// License details
var licenseNamesElement = propertiesElement.Element(dataservices + licenseNamesProperty);
var licenseNames = licenseNamesElement?.Value;

var licenseReportUrlElement = propertiesElement.Element(dataservices + licenseReportUrlProperty);
var licenseReportUrl = licenseReportUrlElement?.Value;

// NOTE that DateTime returned by the v2 feed does not have Z at the end even though it is in UTC. So, the DateTime kind is unspecified
// So, forcibly convert it to UTC here
createdDate = createdDate.ForceUtc();
lastEditedDate = lastEditedDate.ForceUtc();
publishedDate = publishedDate.ForceUtc();

packages.Add(new FeedPackageDetails(
content,
createdDate,
lastEditedDate,
publishedDate,
packageId,
packageNormalizedVersion,
licenseNames,
licenseReportUrl,
deprecationInfo: null));
}

return packages;
}
}
}
8 changes: 6 additions & 2 deletions src/Catalog/Helpers/FeedPackageDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class FeedPackageDetails
public string PackageVersion { get; }
public string LicenseNames { get; }
public string LicenseReportUrl { get; }
public bool RequiresLicenseAcceptance { get; }
public PackageDeprecationItem DeprecationInfo { get; }

public bool HasDeprecationInfo => DeprecationInfo != null;
Expand All @@ -35,7 +36,8 @@ public FeedPackageDetails(
packageVersion,
licenseNames: null,
licenseReportUrl: null,
deprecationInfo: null)
deprecationInfo: null,
requiresLicenseAcceptance: false)
{
}

Expand All @@ -48,7 +50,8 @@ public FeedPackageDetails(
string packageVersion,
string licenseNames,
string licenseReportUrl,
PackageDeprecationItem deprecationInfo)
PackageDeprecationItem deprecationInfo,
bool requiresLicenseAcceptance)
{
ContentUri = contentUri;
CreatedDate = createdDate;
Expand All @@ -59,6 +62,7 @@ public FeedPackageDetails(
LicenseNames = licenseNames;
LicenseReportUrl = licenseReportUrl;
DeprecationInfo = deprecationInfo;
RequiresLicenseAcceptance = requiresLicenseAcceptance;
}
}
}
1 change: 1 addition & 0 deletions src/Catalog/Helpers/GalleryDatabaseQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class GalleryDatabaseQueryService : IGalleryDatabaseQueryService
P.[HideLicenseReport],
P.[LicenseNames],
P.[LicenseReportUrl],
P.[RequiresLicenseAcceptance],
PD.[Status] AS '{Db2CatalogProjectionColumnNames.DeprecationStatus}',
APR.[Id] AS '{Db2CatalogProjectionColumnNames.AlternatePackageId}',
AP.[NormalizedVersion] AS '{Db2CatalogProjectionColumnNames.AlternatePackageVersion}',
Expand Down
2 changes: 0 additions & 2 deletions src/Catalog/Helpers/JsonSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Services.Metadata.Catalog.Helpers
{
Expand Down
2 changes: 0 additions & 2 deletions src/Catalog/Helpers/UriUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NuGet.Versioning;

namespace NuGet.Services.Metadata.Catalog.Helpers
Expand Down
2 changes: 0 additions & 2 deletions src/Catalog/Helpers/XsltHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.XPath;
using NuGet.Services.Metadata.Catalog.Helpers;
Expand Down
5 changes: 3 additions & 2 deletions src/Catalog/PackageCatalogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ public override IGraph CreateContentGraph(CatalogContext context)
return graph;
}

private bool GetListed(DateTime published)
public static bool GetListed(DateTime published)
{
//If the published date is 1900/01/01, then the package is unlisted
if (published.ToUniversalTime() == Convert.ToDateTime("1900-01-01T00:00:00Z").ToUniversalTime())
if (published.ToUniversalTime() == Constants.UnpublishedDate)
{
return false;
}

return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/Catalog/SingleGraphPersistence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using NuGet.Services.Metadata.Catalog.Persistence;
using VDS.RDF;

Expand Down
1 change: 0 additions & 1 deletion src/Catalog/VerboseFileSystemEmulatorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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.Diagnostics;
using System.Net.Http;
using System.Threading;
Expand Down
1 change: 0 additions & 1 deletion src/Ng/Jobs/Catalog2PackageFixupJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
Expand Down
1 change: 0 additions & 1 deletion src/Ng/Jobs/ClearLuceneJob.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Threading;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion src/Ng/Jobs/MonitoringProcessorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected override async Task RunInternalAsync(CancellationToken cancellationTok

private async Task ProcessPackagesAsync(CancellationToken token)
{
StorageQueueMessage<PackageValidatorContext> queueMessage = null;
StorageQueueMessage<PackageValidatorContext> queueMessage;
do
{
Logger.LogInformation("Fetching next queue message.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
Expand Down
2 changes: 0 additions & 2 deletions src/NuGet.Indexing/ChainedFilter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.Linq;
using System.Text;

using Lucene.Net.Search;
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/DescriptionAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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 Lucene.Net.Analysis;
using System.Collections.Generic;
using System.IO;

namespace NuGet.Indexing
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/DownloadsByVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace NuGet.Indexing
{
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/FileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Newtonsoft.Json;
using System.IO;
using System;
using System.Threading.Tasks;

namespace NuGet.Indexing
{
Expand Down
4 changes: 0 additions & 4 deletions src/NuGet.Indexing/IndexConsistencyReport.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// 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.Linq;
using System.Text;
using Newtonsoft.Json.Linq;

namespace NuGet.Indexing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Lucene.Net.Store;
using Lucene.Net.Store;

namespace NuGet.Indexing.IndexDirectoryProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Lucene.Net.Store;
using Lucene.Net.Store;

namespace NuGet.Indexing.IndexDirectoryProvider
{
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/KeyCollector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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 Lucene.Net.Search;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;

namespace NuGet.Indexing
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/OwnerAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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 Lucene.Net.Analysis;
using System.Collections.Generic;
using System.IO;

namespace NuGet.Indexing
Expand Down
3 changes: 0 additions & 3 deletions src/NuGet.Indexing/PerfEventTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Indexing
{
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/SearcherManagerT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using System.Threading.Tasks;

namespace NuGet.Indexing
{
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/SegmentInfoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;

namespace NuGet.Indexing
{
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Indexing/TenantFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;
using System;

namespace NuGet.Indexing
{
Expand Down
2 changes: 0 additions & 2 deletions src/NuGet.Indexing/TypeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;
using System;

namespace NuGet.Indexing
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using NuGet.Services.Configuration;
using NuGet.Services.KeyVault;
Expand Down
Loading

0 comments on commit 45f07fe

Please sign in to comment.