Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Controllers/ResourceGroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public async Task<IActionResult> Details(string name)
return View(resources);
}

public async Task<IActionResult> ManagementGroups()
{
var azureManagementGroups = await GetAzureManagementGroups();
return View(azureManagementGroups);
}

public async Task<IActionResult> Index()
{
var resourceGroups = await GetResourceGroupsAsync();
Expand Down Expand Up @@ -81,6 +87,36 @@ private async Task<List<AzureResource>> GetResourcesAsync(string name)
}
return theResources;
}

private async Task<List<AzureManagementGroup>> GetAzureManagementGroups()
{
var httpClient = _httpClientFactory.CreateClient("AzureServices");

var httpResponseMessage = await httpClient.GetAsync(
$"managementgroups?api-version=2021-04-01");

var jsonDocument = JsonDocument.Parse(httpResponseMessage.Content.ReadAsStringAsync().Result);

var azureManagementGroups = new List<AzureManagementGroup>();

if (jsonDocument.RootElement.TryGetProperty("value", out JsonElement managementGroupsElement))
{
foreach (var managementGroup in managementGroupsElement.EnumerateArray())
{
var name = managementGroup.GetProperty("name").GetString();
var id = managementGroup.GetProperty("id").GetString();
var type = managementGroup.GetProperty("type").GetString();
azureManagementGroups.Add(new AzureManagementGroup
{
Name = name ?? string.Empty,
Type = type ?? string.Empty,
Id = id ?? string.Empty,

});
}
}
return azureManagementGroups;
}
}
}

7 changes: 5 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
var builder = WebApplication.CreateBuilder(args);

IConfiguration _configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();

.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();


var clientId = _configuration["ClientId"];
var clientSecret = _configuration["ClientSecret"];
Expand Down
15 changes: 15 additions & 0 deletions Services/ResourceGroupsClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ public class ResourceGroup
public string? Location { get; set; }
}

public class AzureManagementGroup
{
public string? Id { get; set; }
public string? Type { get; set; }
public string? Name { get; set; }
}

public class AzureResource
{
Expand All @@ -14,5 +20,14 @@ public class AzureResource
public string? Type { get; set; }
public string? Location { get; set; }
public Dictionary<string, string>? Tags { get; set; }
public string? Url
{
get
{
string[] parts = Type?.Split('/') ?? new string[0];
return $"/images/{parts[0]}/{parts[1]}.svg";

}
}
}
}
2 changes: 1 addition & 1 deletion Views/ResourceGroups/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<ul>
@foreach (var resource in Model)
{
<li>@resource.Name (@resource.Type)</li>
<li><img src="@resource.Url" /> @resource.Name </li>
}
</ul>
10 changes: 10 additions & 0 deletions Views/ResourceGroups/ManagementGroups.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@model List<AzureIntegration.Services.AzureManagementGroup>

<h2>Management groups:</h2>

<ul>
@foreach (var group in Model)
{
<li>@group.Name (@group.Type / @group.Id)</li>
}
</ul>
12 changes: 5 additions & 7 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"AzureAd": {
"ClientId": "",
"ClientSecret": "",
"TenantId": "",
"SubscriptionId": ""
},
"ClientId": "",
"ClientSecret": "",
"TenantId": "",
"SubscriptionId": "",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
}
1 change: 1 addition & 0 deletions wwwroot/images/microsoft.cognitiveservices/accounts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions wwwroot/images/microsoft.compute/disks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions wwwroot/images/microsoft.insights/components.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions wwwroot/images/microsoft.storage/storageaccounts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.