@@ -22,6 +22,12 @@ public async Task<IActionResult> Details(string name)
2222 return View ( resources ) ;
2323 }
2424
25+ public async Task < IActionResult > ManagementGroups ( )
26+ {
27+ var azureManagementGroups = await GetAzureManagementGroups ( ) ;
28+ return View ( azureManagementGroups ) ;
29+ }
30+
2531 public async Task < IActionResult > Index ( )
2632 {
2733 var resourceGroups = await GetResourceGroupsAsync ( ) ;
@@ -81,6 +87,36 @@ private async Task<List<AzureResource>> GetResourcesAsync(string name)
8187 }
8288 return theResources ;
8389 }
90+
91+ private async Task < List < AzureManagementGroup > > GetAzureManagementGroups ( )
92+ {
93+ var httpClient = _httpClientFactory . CreateClient ( "AzureServices" ) ;
94+
95+ var httpResponseMessage = await httpClient . GetAsync (
96+ $ "managementgroups?api-version=2021-04-01") ;
97+
98+ var jsonDocument = JsonDocument . Parse ( httpResponseMessage . Content . ReadAsStringAsync ( ) . Result ) ;
99+
100+ var azureManagementGroups = new List < AzureManagementGroup > ( ) ;
101+
102+ if ( jsonDocument . RootElement . TryGetProperty ( "value" , out JsonElement managementGroupsElement ) )
103+ {
104+ foreach ( var managementGroup in managementGroupsElement . EnumerateArray ( ) )
105+ {
106+ var name = managementGroup . GetProperty ( "name" ) . GetString ( ) ;
107+ var id = managementGroup . GetProperty ( "id" ) . GetString ( ) ;
108+ var type = managementGroup . GetProperty ( "type" ) . GetString ( ) ;
109+ azureManagementGroups . Add ( new AzureManagementGroup
110+ {
111+ Name = name ?? string . Empty ,
112+ Type = type ?? string . Empty ,
113+ Id = id ?? string . Empty ,
114+
115+ } ) ;
116+ }
117+ }
118+ return azureManagementGroups ;
119+ }
84120 }
85121}
86122
0 commit comments