Skip to content

Commit f04a69e

Browse files
committed
C#: Parse environment variables to obtain list of registry URLs
1 parent dd96330 commit f04a69e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Security.Cryptography.X509Certificates;
55
using Semmle.Util;
66
using Semmle.Util.Logging;
7+
using Newtonsoft.Json;
78

89
namespace Semmle.Extraction.CSharp.DependencyFetching
910
{
@@ -86,6 +87,39 @@ public struct RegistryConfig
8687
result.Certificate = X509Certificate2.CreateFromPem(cert);
8788
}
8889

90+
// Try to obtain the list of private registry URLs.
91+
var registryURLs = Environment.GetEnvironmentVariable(EnvironmentVariableNames.ProxyURLs);
92+
93+
if (!string.IsNullOrWhiteSpace(registryURLs))
94+
{
95+
try
96+
{
97+
// The value of the environment variable should be a JSON array of objects, such as:
98+
// [ { "type": "nuget_feed", "url": "https://nuget.pkg.github.com/org/index.json" } ]
99+
var array = JsonConvert.DeserializeObject<List<RegistryConfig>>(registryURLs);
100+
if (array != null)
101+
{
102+
foreach (RegistryConfig config in array)
103+
{
104+
// The array contains all configured private registries, not just ones for C#.
105+
// We ignore the non-C# ones here.
106+
if (!config.Type.Equals("nuget_feed"))
107+
{
108+
logger.LogDebug($"Ignoring registry at '{config.URL}' since it is not of type 'nuget_feed'.");
109+
continue;
110+
}
111+
112+
logger.LogInfo($"Found private registry at '{config.URL}'");
113+
result.RegistryURLs.Add(config.URL);
114+
}
115+
}
116+
}
117+
catch (Exception ex)
118+
{
119+
logger.LogError($"Unable to parse '{EnvironmentVariableNames.ProxyURLs}': {ex.Message}");
120+
}
121+
}
122+
89123
return result;
90124
}
91125

0 commit comments

Comments
 (0)