-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
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,53 @@ | ||
using System; | ||
using System.IO; | ||
using Semmle.Util; | ||
|
||
namespace Semmle.Extraction.CSharp.DependencyFetching | ||
{ | ||
internal class DependabotProxy | ||
{ | ||
private readonly string? host; | ||
private readonly string? port; | ||
private readonly FileInfo? certFile; | ||
|
||
/// <summary> | ||
/// The full address of the Dependabot proxy, if available. | ||
/// </summary> | ||
internal readonly string? Address; | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether a Dependabot proxy is configured. | ||
/// </summary> | ||
internal bool IsConfigured => !string.IsNullOrEmpty(this.Address); | ||
|
||
internal DependabotProxy(TemporaryDirectory tempWorkingDirectory) | ||
{ | ||
// Obtain and store the address of the Dependabot proxy, if available. | ||
this.host = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyHost); | ||
this.port = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyPort); | ||
|
||
if (string.IsNullOrWhiteSpace(host) || string.IsNullOrWhiteSpace(port)) | ||
{ | ||
return; | ||
} | ||
|
||
this.Address = $"http://{this.host}:{this.port}"; | ||
|
||
// Obtain and store the proxy's certificate, if available. | ||
var cert = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyCertificate); | ||
|
||
if (string.IsNullOrWhiteSpace(cert)) | ||
{ | ||
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")); | ||
|
||
using var writer = this.certFile.CreateText(); | ||
writer.Write(cert); | ||
} | ||
} | ||
} |