8000 C#: Set proxy environment variables, if Dependabot proxy is detected by mbg · Pull Request #18029 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

C#: Set proxy environment variables, if Dependabot proxy is detected #18029

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

Merged
merged 15 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C#: Propagate DependabotProxy instance down from DependencyManager
  • Loading branch information
mbg committed Dec 5, 2024
commit 984091d4a4cf8fa4e44fed4f22a9cc9f1fa1191d
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Semmle.Extraction.CSharp.DependencyFetching
{
internal class DependabotProxy
public class DependabotProxy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably implement System.Net.IWebProxy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but I am not sure I see any immediate benefit to it. Although I guess it would simplify the implementation for the feed reachability checking? Happy to do that in a follow-up PR if it makes sense, but it would be nice to get this functionality shipped for now.

{
private readonly string? host;
private readonly string? port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed partial class DependencyManager : IDisposable, ICompilationInfoCon
private readonly ILogger logger;
private readonly IDiagnosticsWriter diagnosticsWriter;
private readonly NugetPackageRestorer nugetPackageRestorer;
private readonly DependabotProxy dependabotProxy;
private readonly IDotNet dotnet;
private readonly FileContent fileContent;
private readonly FileProvider fileProvider;
Expand Down Expand Up @@ -106,9 +107,11 @@ void exitCallback(int ret, string msg, bool silent)
return BuildScript.Success;
}).Run(SystemBuildActions.Instance, startCallback, exitCallback);

dependabotProxy = new DependabotProxy(logger, tempWorkingDirectory);

try
{
this.dotnet = DotNet.Make(logger, dotnetPath, tempWorkingDirectory);
this.dotnet = DotNet.Make(logger, dotnetPath, tempWorkingDirectory, dependabotProxy);
runtimeLazy = new Lazy<Runtime>(() => new Runtime(dotnet));
}
catch
Expand All @@ -117,7 +120,7 @@ void exitCallback(int ret, string msg, bool silent)
throw;
}

nugetPackageRestorer = new NugetPackageRestorer(fileProvider, fileContent, dotnet, diagnosticsWriter, logger, this);
nugetPackageRestorer = new NugetPackageRestorer(fileProvider, fileContent, dotnet, dependabotProxy, diagnosticsWriter, logger, this);

var dllLocations = fileProvider.Dlls.Select(x => new AssemblyLookupLocation(x)).ToHashSet();
dllLocations.UnionWith(nugetPackageRestorer.Restore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ private DotNet(IDotNetCliInvoker dotnetCliInvoker, ILogger logger, TemporaryDire
Info();
}

private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory) : this(new DotNetCliInvoker(logger, Path.Combine(dotNetPath ?? string.Empty, "dotnet"), tempWorkingDirectory), logger, tempWorkingDirectory) { }
private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy dependabotProxy) : this(new DotNetCliInvoker(logger, Path.Combine(dotNetPath ?? string.Empty, "dotnet"), dependabotProxy), logger, tempWorkingDirectory) { }

internal static IDotNet Make(IDotNetCliInvoker dotnetCliInvoker, ILogger logger) => new DotNet(dotnetCliInvoker, logger);

public static IDotNet Make(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory) => new DotNet(logger, dotNetPath, tempWorkingDirectory);
public static IDotNet Make(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy dependabotProxy) => new DotNet(logger, dotNetPath, tempWorkingDirectory, dependabotProxy);

private void Info()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ internal sealed class DotNetCliInvoker : IDotNetCliInvoker

public string Exec { get; }

public DotNetCliInvoker(ILogger logger, string exec, TemporaryDirectory tempWorkingDirectory)
public DotNetCliInvoker(ILogger logger, string exec, DependabotProxy dependabotProxy)
{
this.logger = logger;
this.proxy = new DependabotProxy(logger, tempWorkingDirectory);< D5BE /span>
this.proxy = dependabotProxy;
this.Exec = exec;
logger.LogInfo($"Using .NET CLI executable: '{Exec}'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal sealed partial class NugetPackageRestorer : IDisposable
private readonly FileProvider fileProvider;
private readonly FileContent fileContent;
private readonly IDotNet dotnet;
private readonly DependabotProxy dependabotProxy;
private readonly IDiagnosticsWriter diagnosticsWriter;
private readonly TemporaryDirectory legacyPackageDirectory;
private readonly TemporaryDirectory missingPackageDirectory;
Expand All @@ -32,13 +33,15 @@ public NugetPackageRestorer(
FileProvider fileProvider,
FileContent fileContent,
IDotNet dotnet,
DependabotProxy dependabotProxy,
IDiagnosticsWriter diagnosticsWriter,
ILogger logger,
ICompilationInfoContainer compilationInfoContainer)
{
this.fileProvider = fileProvider;
this.fileContent = fileContent;
this.dotnet = dotnet;
this.dependabotProxy = dependabotProxy;
this.diagnosticsWriter = diagnosticsWriter;
this.logger = logger;
this.compilationInfoContainer = compilationInfoContainer;
Expand Down
0