Skip to content

Commit 9c8fe6e

Browse files
authored
Merge pull request #5 from sayedimac/dev
Dev
2 parents 0942f68 + e60dc33 commit 9c8fe6e

File tree

11 files changed

+77
-10
lines changed

11 files changed

+77
-10
lines changed

Controllers/ResourceGroupsController.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
var builder = WebApplication.CreateBuilder(args);
55

66
IConfiguration _configuration = new ConfigurationBuilder()
7-
.AddEnvironmentVariables()
8-
.Build();
7+
8+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
9+
.AddEnvironmentVariables()
10+
.Build();
11+
912

1013
var clientId = _configuration["ClientId"];
1114
var clientSecret = _configuration["ClientSecret"];

Services/ResourceGroupsClasses.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ public class ResourceGroup
66
public string? Location { get; set; }
77
}
88

9+
public class AzureManagementGroup
10+
{
11+
public string? Id { get; set; }
12+
public string? Type { get; set; }
13+
public string? Name { get; set; }
14+
}
915

1016
public class AzureResource
1117
{
@@ -14,5 +20,14 @@ public class AzureResource
1420
public string? Type { get; set; }
1521
public string? Location { get; set; }
1622
public Dictionary<string, string>? Tags { get; set; }
23+
public string? Url
24+
{
25+
get
26+
{
27+
string[] parts = Type?.Split('/') ?? new string[0];
28+
return $"/images/{parts[0]}/{parts[1]}.svg";
29+
30+
}
31+
}
1732
}
1833
}

Views/ResourceGroups/Details.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<ul>
66
@foreach (var resource in Model)
77
{
8-
<li>@resource.Name (@resource.Type)</li>
8+
<li><img src="@resource.Url" /> @resource.Name </li>
99
}
1010
</ul>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@model List<AzureIntegration.Services.AzureManagementGroup>
2+
3+
<h2>Management groups:</h2>
4+
5+
<ul>
6+
@foreach (var group in Model)
7+
{
8+
<li>@group.Name (@group.Type / @group.Id)</li>
9+
}
10+
</ul>

appsettings.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
2-
"AzureAd": {
3-
"ClientId": "",
4-
"ClientSecret": "",
5-
"TenantId": "",
6-
"SubscriptionId": ""
7-
},
2+
"ClientId": "",
3+
"ClientSecret": "",
4+
"TenantId": "",
5+
"SubscriptionId": "",
86
"Logging": {
97
"LogLevel": {
108
"Default": "Information",
119
"Microsoft.AspNetCore": "Warning"
1210
}
1311
},
1412
"AllowedHosts": "*"
15-
}
13+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)