11using Microsoft . AspNetCore . Mvc ;
22using System . Text . Json ;
33using AzureIntegration . Services ;
4+ using Microsoft . VisualBasic ;
5+ using System . Runtime . CompilerServices ;
6+
47
58namespace AzureIntegration . Controllers
69{
710
811 public class ResourceGroupsController : Controller
9-
1012 {
1113 private readonly IHttpClientFactory _httpClientFactory ;
1214 private readonly IConfiguration _configuration ;
15+
1316 public ResourceGroupsController ( IHttpClientFactory httpClientFactory , IConfiguration configuration )
1417 {
1518 _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException ( nameof ( httpClientFactory ) ) ;
@@ -37,9 +40,9 @@ public async Task<IActionResult> Index()
3740 private async Task < List < ResourceGroup > > GetResourceGroupsAsync ( )
3841 {
3942 var httpClient = _httpClientFactory . CreateClient ( "AzureServices" ) ;
40-
43+ var subscriptionId = _configuration [ "SubscriptionId" ] ;
4144 var httpResponseMessage = await httpClient . GetAsync (
42- $ "resourcegroups?api-version=2021-04-01") ;
45+ $ "subscriptions/ { subscriptionId } / resourcegroups?api-version=2021-04-01") ;
4346
4447
4548 var jsonDocument = JsonDocument . Parse ( httpResponseMessage . Content . ReadAsStringAsync ( ) . Result ) ;
@@ -67,9 +70,10 @@ private async Task<List<AzureResource>> GetResourcesAsync(string name)
6770 {
6871
6972 var httpClient = _httpClientFactory . CreateClient ( "AzureServices" ) ;
73+ var subscriptionId = _configuration [ "SubscriptionId" ] ;
7074
7175 var httpResponseMessage = await httpClient . GetAsync (
72- $ "resourceGroups/{ name } /resources?api-version=2021-04-01") ;
76+ $ "subscriptions/ { subscriptionId } / resourceGroups/{ name } /resources?api-version=2021-04-01") ;
7377
7478 var jsonDocument = JsonDocument . Parse ( httpResponseMessage . Content . ReadAsStringAsync ( ) . Result ) ;
7579
@@ -93,7 +97,7 @@ private async Task<List<AzureManagementGroup>> GetAzureManagementGroups()
9397 var httpClient = _httpClientFactory . CreateClient ( "AzureServices" ) ;
9498
9599 var httpResponseMessage = await httpClient . GetAsync (
96- $ "managementgroups ?api-version=2021-04 -01") ;
100+ $ "providers/Microsoft.Management/managementGroups ?api-version=2020-05 -01") ;
97101
98102 var jsonDocument = JsonDocument . Parse ( httpResponseMessage . Content . ReadAsStringAsync ( ) . Result ) ;
99103
@@ -103,7 +107,8 @@ private async Task<List<AzureManagementGroup>> GetAzureManagementGroups()
103107 {
104108 foreach ( var managementGroup in managementGroupsElement . EnumerateArray ( ) )
105109 {
106- var name = managementGroup . GetProperty ( "name" ) . GetString ( ) ;
110+ var name = managementGroup . GetProperty ( "properties" ) . GetProperty ( "displayName" ) . GetString ( ) ;
111+ //var name = managementGroup. .GetProperty("displayName").GetString();
107112 var id = managementGroup . GetProperty ( "id" ) . GetString ( ) ;
108113 var type = managementGroup . GetProperty ( "type" ) . GetString ( ) ;
109114 azureManagementGroups . Add ( new AzureManagementGroup
@@ -117,6 +122,7 @@ private async Task<List<AzureManagementGroup>> GetAzureManagementGroups()
117122 }
118123 return azureManagementGroups ;
119124 }
125+
120126 }
121127}
122128
0 commit comments