C#: Add more logging to DependabotProxy

This commit is contained in:
Michael B. Gale
2024-11-29 13:18:58 +00:00
parent 6cd5711313
commit de415d68cf
2 changed files with 9 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
/// </summary>
internal bool IsConfigured => !string.IsNullOrEmpty(this.Address);
internal DependabotProxy(TemporaryDirectory tempWorkingDirectory)
internal DependabotProxy(ILogger logger, TemporaryDirectory tempWorkingDirectory)
{
// Obtain and store the address of the Dependabot proxy, if available.
this.host = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyHost);
@@ -30,26 +30,32 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
if (string.IsNullOrWhiteSpace(host) || string.IsNullOrWhiteSpace(port))
{
logger.LogInfo("No Dependabot proxy credentials are configured.");
return;
}
this.Address = $"http://{this.host}:{this.port}";
logger.LogInfo($"Dependabot proxy configured at {this.Address}");
// Obtain and store the proxy's certificate, if available.
var cert = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyCertificate);
if (string.IsNullOrWhiteSpace(cert))
{
logger.LogInfo("No certificate configured for Dependabot proxy.");
return;
}
var certDirPath = new DirectoryInfo(Path.Join(tempWorkingDirectory.DirInfo.FullName, ".dependabot-proxy"));
Directory.CreateDirectory(certDirPath.FullName);
this.certFile = new FileInfo(Path.Join(certDirPath.FullName, "proxy.crt"));
var certFilePath = Path.Join(certDirPath.FullName, "proxy.crt");
this.certFile = new FileInfo(certFilePath);
using var writer = this.certFile.CreateText();
writer.Write(cert);
logger.LogInfo($"Stored Dependabot proxy certificate at {certFilePath}");
}
internal void ApplyProxy(ILogger logger, ProcessStartInfo startInfo)

View File

@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
public DotNetCliInvoker(ILogger logger, string exec, TemporaryDirectory tempWorkingDirectory)
{
this.logger = logger;
this.proxy = new DependabotProxy(tempWorkingDirectory);
this.proxy = new DependabotProxy(logger, tempWorkingDirectory);
this.Exec = exec;
logger.LogInfo($"Using .NET CLI executable: '{Exec}'");
}