Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
C#: Support replaces-base via the DependabotProxy.#22494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
michaelnebel
wants to merge
8
commits into
github:mainChoose a base branch
from
michaelnebel:csharp/replaces-base
base:main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Uh oh!
There was an error while loading. Please reload this page.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
74d2612
C#: DependabotProxy now parses replaces-base and exposes a list of UR…
michaelnebel 1cf5d23
C#: Use the RegistryUrls from the dependabot proxy as default feeds i…
michaelnebel f10882c
C#: Add change-note.
michaelnebel 1b1a22a
C#: Preserve semantics of reachability for default feeds when using […
michaelnebel d6ae24f
C#: Remove isNullOrEmpty check as it is implied by the case above.
michaelnebel 6e71be1
C#: Make a complete replacement of the default nuget.org feed in case…
michaelnebel ae89e13
C#: Exclude TryRestoreManually fallback without nugetSources when pri…
michaelnebel 983dbbc
C#: Minor improvements to unit test.
michaelnebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
37 changes: 32 additions & 5 deletions
37 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
This file contains hidden or 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
1 change: 0 additions & 1 deletion
1 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/EnvironmentVariableNames.cs
This file contains hidden or 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
74 changes: 52 additions & 22 deletions
74 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -10,13 +10,17 @@ namespace Semmle.Extraction.CSharp.DependencyFetching | ||
| { | ||
| internal sealed partial class FeedManager : IDisposable | ||
| { | ||
| internal const string PublicNugetOrgFeed = "https://api.nuget.org/v3/index.json"; | ||
| private const string PublicNugetOrg = "nuget.org"; | ||
| private const string PublicDotNugetOrg = $".{PublicNugetOrg}"; | ||
| internal const string PublicApiNugetOrgFeed = $"https://api{PublicDotNugetOrg}/v3/index.json"; | ||
| private readonly ILogger logger; | ||
| private readonly IDotNet dotnet; | ||
| private readonly IFileProvider fileProvider; | ||
| private readonly DependencyDirectory emptyPackageDirectory; | ||
| private readonly ImmutableHashSet<string> privateRegistryFeeds; | ||
| private readonly bool hasPrivateRegistryBaseFeeds; | ||
| private readonly ImmutableHashSet<string> privateRegistryBaseFeeds; | ||
| private readonly IFeedManagerIO feedManagerIo; | ||
| /// <summary> | ||
| @@ -72,14 +76,33 @@ internal sealed partial class FeedManager : IDisposable | ||
| /// </summary> | ||
| public ImmutableHashSet<string> ReachableFallbackFeeds => lazyReachableFallbackFeeds.Value; | ||
| private readonly Lazy<ImmutableHashSet<string>> lazyReachableDefaultFeeds; | ||
| /// <summary> | ||
| /// Gets the list of default NuGet feeds that are configured in the environment. | ||
| /// This is either the public NuGet feed or a set of feeds specified by the environment. | ||
| /// </summary> | ||
| public ImmutableHashSet<string> DefaultFeeds { get; init; } | ||
| /// <summary> | ||
| /// Gets the list of reachable default NuGet feeds. | ||
| /// </summary> | ||
| public ImmutableHashSet<string> ReachableDefaultFeeds => lazyReachableDefaultFeeds.Value; | ||
| public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotProxy, IFileProvider fileProvider, IFeedManagerIO feedManagerIo) | ||
| { | ||
| this.logger = logger; | ||
| this.dotnet = dotnet; | ||
| this.fileProvider = fileProvider; | ||
| this.feedManagerIo = feedManagerIo; | ||
| privateRegistryFeeds = dependabotProxy?.RegistryURLs.ToImmutableHashSet() ?? []; | ||
| privateRegistryFeeds = dependabotProxy?.RegistryURLs ?? []; | ||
| HasPrivateRegistryFeeds = privateRegistryFeeds.Count > 0; | ||
| privateRegistryBaseFeeds = dependabotProxy?.RegistryBaseURLs ?? []; | ||
| hasPrivateRegistryBaseFeeds = privateRegistryBaseFeeds.Count > 0; | ||
| DefaultFeeds = hasPrivateRegistryBaseFeeds | ||
| ? privateRegistryBaseFeeds | ||
| : [PublicApiNugetOrgFeed]; | ||
| emptyPackageDirectory = new DependencyDirectory("empty", "empty package", logger); | ||
| lazyExplicitFeeds = new Lazy<ImmutableHashSet<string>>(GetExplicitFeeds); | ||
| @@ -96,13 +119,28 @@ public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotP | ||
| var reachableFallbackFeeds = GetReachableFallbackNugetFeeds(); | ||
| return reachableFallbackFeeds.ToImmutableHashSet(); | ||
| }); | ||
| lazyReachableDefaultFeeds = new Lazy<ImmutableHashSet<string>>(() => CheckSpecifiedFeeds(DefaultFeeds)); | ||
| } | ||
| public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotProxy, IFileProvider fileProvider) | ||
| : this(logger, dotnet, dependabotProxy, fileProvider, new FeedManagerIO(logger, dependabotProxy)) | ||
| { | ||
| } | ||
| private bool IsNugetOrgFeed(string url) | ||
| { | ||
| try | ||
| { | ||
| var uri = new Uri(url); | ||
| return uri.Host.EndsWith(PublicDotNugetOrg, StringComparison.InvariantCultureIgnoreCase) || | ||
| string.Equals(uri.Host, PublicNugetOrg, StringComparison.InvariantCultureIgnoreCase); | ||
| } | ||
| catch (UriFormatException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| private IEnumerable<string> GetFeeds(Func<IList<string>> getNugetFeeds) | ||
| { | ||
| var results = getNugetFeeds(); | ||
| @@ -124,10 +162,18 @@ private IEnumerable<string> GetFeeds(Func<IList<string>> getNugetFeeds) | ||
| continue; | ||
| } | ||
| if (!string.IsNullOrWhiteSpace(url)) | ||
| if (hasPrivateRegistryBaseFeeds && IsNugetOrgFeed(url)) | ||
| { | ||
| yield return url; | ||
| // Use private registry base feeds. | ||
| foreach (var feed in privateRegistryBaseFeeds) | ||
| { | ||
| logger.LogDebug($"Using private registry base feed '{feed}'."); | ||
| yield return feed; | ||
| } | ||
| continue; | ||
| } | ||
| yield return url; | ||
| } | ||
| } | ||
| @@ -266,22 +312,6 @@ private ImmutableHashSet<string> CheckSpecifiedFeeds(ImmutableHashSet<string> fe | ||
| return reachable.Union(feeds.Where(feed => excludedFeeds.Contains(feed))).ToImmutableHashSet(); | ||
| } | ||
| /// <summary> | ||
| /// Return true if the default NuGet feed is reachable, false otherwise. | ||
| /// If the reachability check is disabled, this method will always return true. | ||
| /// </summary> | ||
| /// <returns>True if the default NuGet feed is reachable, false otherwise.</returns> | ||
| public bool IsDefaultFeedReachable() | ||
| { | ||
| if (CheckNugetFeedResponsiveness) | ||
| { | ||
| var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback: false); | ||
| return feedManagerIo.IsFeedReachable(PublicNugetOrgFeed, initialTimeout, tryCount); | ||
| } | ||
| return true; | ||
| } | ||
| /// <summary> | ||
| /// Tests which of the feeds given by <paramref name="feedsToCheck"/> are reachable. | ||
| /// </summary> | ||
| @@ -315,8 +345,8 @@ private List<string> GetReachableFallbackNugetFeeds() | ||
| var fallbackFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.FallbackNugetFeeds).ToHashSet(); | ||
| if (fallbackFeeds.Count == 0) | ||
| { | ||
| fallbackFeeds.Add(PublicNugetOrgFeed); | ||
| logger.LogInfo($"No fallback NuGet feeds specified. Adding default feed: {PublicNugetOrgFeed}"); | ||
| fallbackFeeds.UnionWith(DefaultFeeds); | ||
| logger.LogInfo($"No fallback NuGet feeds specified. Adding default feeds: {string.Join(", ", DefaultFeeds.OrderBy(f => f))}"); | ||
michaelnebel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| var shouldAddNugetConfigFeeds = EnvironmentVariables.GetBooleanOptOut(EnvironmentVariableNames.AddNugetConfigFeedsToFallback); | ||
| logger.LogInfo($"Adding feeds from nuget.config to fallback restore: {shouldAddNugetConfigFeeds}"); | ||
9 changes: 7 additions & 2 deletions
9 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDependabotProxy.cs
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
This file contains hidden or 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
17 changes: 8 additions & 9 deletions
17 csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/PackagesConfigRestorer.cs
This file contains hidden or 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
31 changes: 30 additions & 1 deletion
31 csharp/extractor/Semmle.Extraction.Tests/DependabotProxy.cs
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.