11using System ;
2+ using System . Collections . Immutable ;
23using System . Collections . Generic ;
34using System . IO ;
45using System . Security . Cryptography . X509Certificates ;
@@ -14,13 +15,39 @@ public class DependabotProxy : IDependabotProxy
1415 /// <summary>
1516 /// Represents configurations for package registries.
1617 /// </summary>
17- /// <param name="Type">The type of package registry.</param>
18- /// <param name="URL">The URL of the package registry.</param>
19- public record class RegistryConfig ( string Type , string URL ) ;
18+ public class RegistryConfig
19+ {
20+ /// <summary>
21+ /// The type of the package registry.
22+ /// </summary>
23+ public string Type { get ; init ; } = "" ;
24+
25+ /// <summary>
26+ /// The URL of the package registry.
27+ /// </summary>
28+ public string URL { get ; init ; } = "" ;
29+
30+ /// <summary>
31+ /// A boolean indicating whether this registry replaces the base registry.
32+ /// </summary>
33+ [ JsonProperty ( "replaces-base" ) ]
34+ public bool ReplacesBase { get ; init ; } = false ;
35+ } ;
2036
2137 public string Address { get ; }
2238
23- public HashSet < string > RegistryURLs { get ; } = [ ] ;
39+ /// <summary>
40+ /// A dictionary mapping registry URLs to a boolean indicating whether they replace the base registry.
41+ /// </summary>
42+ private readonly Dictionary < string , bool > registryMapping = [ ] ;
43+
44+ private ImmutableHashSet < string > ? registryURLs ;
45+ public ImmutableHashSet < string > RegistryURLs =>
46+ registryURLs ??= registryMapping . Keys . ToImmutableHashSet ( ) ;
47+
48+ private ImmutableHashSet < string > ? registryBaseURLs ;
49+ public ImmutableHashSet < string > RegistryBaseURLs =>
50+ registryBaseURLs ??= registryMapping . Where ( kvp => kvp . Value ) . Select ( kvp => kvp . Key ) . ToImmutableHashSet ( ) ;
2451
2552 public string ? CertificatePath { get ; private set ; }
2653
@@ -65,7 +92,7 @@ private DependabotProxy(IDependabotProxyConfiguration config, ILogger logger, Te
6592 }
6693
6794 logger . LogInfo ( $ "Found private registry at '{ registry . URL } '") ;
68- RegistryURLs . Add ( registry . URL ) ;
95+ registryMapping . AddOrUpdateToLatest ( registry . URL , registry . ReplacesBase ) ;
6996 }
7097 }
7198 }
0 commit comments