@@ -14,6 +14,8 @@ public interface IAvmModuleDisplayNameProvider
1414 void StartCache ( ) ;
1515
1616 bool TryGetModuleDisplayName ( string modulePath , [ NotNullWhen ( true ) ] out string ? displayName ) ;
17+
18+ bool TryGetModuleStatus ( string modulePath , [ NotNullWhen ( true ) ] out string ? moduleStatus ) ;
1719 }
1820
1921 public class AvmModuleDisplayNameProvider : IAvmModuleDisplayNameProvider
@@ -22,12 +24,12 @@ public class AvmModuleDisplayNameProvider : IAvmModuleDisplayNameProvider
2224 private static readonly Uri PatternModulesCsvUri = new ( "https://azure.github.io/Azure-Verified-Modules/module-indexes/BicepPatternModules.csv" ) ;
2325 private static readonly Uri ResourceModulesCsvUri = new ( "https://azure.github.io/Azure-Verified-Modules/module-indexes/BicepResourceModules.csv" ) ;
2426
25- private static readonly AvmDisplayNameLookup EmptyLookup = new ( [ ] , [ ] , [ ] ) ;
27+ private static readonly AvmModuleInfoLookup EmptyLookup = new ( [ ] , [ ] , [ ] ) ;
2628
2729 private readonly IAvmModuleCsvIndexHttpClient client ;
2830 private readonly object startLock = new ( ) ;
2931
30- private volatile AvmDisplayNameLookup lookup = EmptyLookup ;
32+ private volatile AvmModuleInfoLookup lookup = EmptyLookup ;
3133 private Task ? loadTask ;
3234
3335 public AvmModuleDisplayNameProvider ( IAvmModuleCsvIndexHttpClient client )
@@ -47,28 +49,52 @@ public bool TryGetModuleDisplayName(string modulePath, [NotNullWhen(true)] out s
4749 {
4850 displayName = null ;
4951
52+ if ( TryGetModuleInfo ( modulePath ) is { } info )
53+ {
54+ displayName = info . DisplayName ;
55+ return true ;
56+ }
57+
58+ return false ;
59+ }
60+
61+ public bool TryGetModuleStatus ( string modulePath , [ NotNullWhen ( true ) ] out string ? moduleStatus )
62+ {
63+ moduleStatus = null ;
64+
65+ if ( TryGetModuleInfo ( modulePath ) is { } info && info . ModuleStatus is not null )
66+ {
67+ moduleStatus = info . ModuleStatus ;
68+ return true ;
69+ }
70+
71+ return false ;
72+ }
73+
74+ private AvmModuleInfo ? TryGetModuleInfo ( string modulePath )
75+ {
5076 if ( TryGetNormalizedModuleName ( modulePath ) is not { } normalizedModuleName )
5177 {
52- return false ;
78+ return null ;
5379 }
5480
5581 var currentLookup = lookup ;
5682 if ( normalizedModuleName . StartsWith ( "avm/utl/" , StringComparison . Ordinal ) )
5783 {
58- return currentLookup . Utility . TryGetValue ( normalizedModuleName , out displayName ) ;
84+ return currentLookup . Utility . TryGetValue ( normalizedModuleName , out var info ) ? info : null ;
5985 }
6086
6187 if ( normalizedModuleName . StartsWith ( "avm/ptn/" , StringComparison . Ordinal ) )
6288 {
63- return currentLookup . Pattern . TryGetValue ( normalizedModuleName , out displayName ) ;
89+ return currentLookup . Pattern . TryGetValue ( normalizedModuleName , out var info ) ? info : null ;
6490 }
6591
6692 if ( normalizedModuleName . StartsWith ( "avm/res/" , StringComparison . Ordinal ) )
6793 {
68- return currentLookup . Resource . TryGetValue ( normalizedModuleName , out displayName ) ;
94+ return currentLookup . Resource . TryGetValue ( normalizedModuleName , out var info ) ? info : null ;
6995 }
7096
71- return false ;
97+ return null ;
7298 }
7399
74100 private async Task LoadAsync ( )
@@ -87,7 +113,7 @@ private async Task LoadAsync()
87113 var pattern = await patternTask ;
88114 var resource = await resourceTask ;
89115
90- lookup = new AvmDisplayNameLookup (
116+ lookup = new AvmModuleInfoLookup (
91117 Utility : utility ,
92118 Pattern : pattern ,
93119 Resource : resource ) ;
@@ -114,7 +140,7 @@ private async Task LoadAsync()
114140 }
115141 }
116142
117- private async Task < ImmutableDictionary < string , string > > LoadCsvAsync ( Uri csvUri , CancellationToken cancellationToken )
143+ private async Task < ImmutableDictionary < string , AvmModuleInfo > > LoadCsvAsync ( Uri csvUri , CancellationToken cancellationToken )
118144 {
119145 var csvContent = await client . GetCsvAsync ( csvUri , cancellationToken ) ;
120146 using var reader = new StringReader ( csvContent ) ;
@@ -140,12 +166,13 @@ private async Task<ImmutableDictionary<string, string>> LoadCsvAsync(Uri csvUri,
140166
141167 var moduleNameIndex = Array . FindIndex ( headers , x => string . Equals ( x , "ModuleName" , StringComparison . Ordinal ) ) ;
142168 var moduleDisplayNameIndex = Array . FindIndex ( headers , x => string . Equals ( x , "ModuleDisplayName" , StringComparison . Ordinal ) ) ;
169+ var moduleStatusIndex = Array . FindIndex ( headers , x => string . Equals ( x , "ModuleStatus" , StringComparison . Ordinal ) ) ;
143170 if ( moduleNameIndex == - 1 || moduleDisplayNameIndex == - 1 )
144171 {
145172 return [ ] ;
146173 }
147174
148- var entries = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
175+ var entries = new Dictionary < string , AvmModuleInfo > ( StringComparer . Ordinal ) ;
149176 while ( ! parser . EndOfData )
150177 {
151178 var fields = parser . ReadFields ( ) ;
@@ -167,7 +194,17 @@ private async Task<ImmutableDictionary<string, string>> LoadCsvAsync(Uri csvUri,
167194 continue ;
168195 }
169196
170- entries . TryAdd ( normalizedModuleName , moduleDisplayName ) ;
197+ string ? moduleStatus = null ;
198+ if ( moduleStatusIndex != - 1 && moduleStatusIndex < fields . Length )
199+ {
200+ var statusValue = fields [ moduleStatusIndex ] ? . Trim ( ) ;
201+ if ( ! string . IsNullOrWhiteSpace ( statusValue ) )
202+ {
203+ moduleStatus = statusValue ;
204+ }
205+ }
206+
207+ entries . TryAdd ( normalizedModuleName , new AvmModuleInfo ( moduleDisplayName , moduleStatus ) ) ;
171208 }
172209
173210 return entries . ToImmutableDictionary ( StringComparer . Ordinal ) ;
@@ -189,10 +226,12 @@ private async Task<ImmutableDictionary<string, string>> LoadCsvAsync(Uri csvUri,
189226 return normalized ;
190227 }
191228
192- private sealed record AvmDisplayNameLookup (
193- ImmutableDictionary < string , string > Utility ,
194- ImmutableDictionary < string , string > Pattern ,
195- ImmutableDictionary < string , string > Resource ) ;
229+ private sealed record AvmModuleInfo ( string DisplayName , string ? ModuleStatus ) ;
230+
231+ private sealed record AvmModuleInfoLookup (
232+ ImmutableDictionary < string , AvmModuleInfo > Utility ,
233+ ImmutableDictionary < string , AvmModuleInfo > Pattern ,
234+ ImmutableDictionary < string , AvmModuleInfo > Resource ) ;
196235 }
197236
198237 public interface IAvmModuleCsvIndexHttpClient
@@ -232,5 +271,11 @@ public bool TryGetModuleDisplayName(string modulePath, [NotNullWhen(true)] out s
232271 displayName = null ;
233272 return false ;
234273 }
274+
275+ public bool TryGetModuleStatus ( string modulePath , [ NotNullWhen ( true ) ] out string ? moduleStatus )
276+ {
277+ moduleStatus = null ;
278+ return false ;
279+ }
235280 }
236281}
0 commit comments