diff --git a/Controllers/ResourceGroupsController.cs b/Controllers/ResourceGroupsController.cs index d796fea..54fabe6 100644 --- a/Controllers/ResourceGroupsController.cs +++ b/Controllers/ResourceGroupsController.cs @@ -22,6 +22,12 @@ public async Task Details(string name) return View(resources); } + public async Task ManagementGroups() + { + var azureManagementGroups = await GetAzureManagementGroups(); + return View(azureManagementGroups); + } + public async Task Index() { var resourceGroups = await GetResourceGroupsAsync(); @@ -81,6 +87,36 @@ private async Task> GetResourcesAsync(string name) } return theResources; } + + private async Task> 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(); + + 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; + } } } diff --git a/Program.cs b/Program.cs index 364f37b..cb541eb 100644 --- a/Program.cs +++ b/Program.cs @@ -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"]; diff --git a/Services/ResourceGroupsClasses.cs b/Services/ResourceGroupsClasses.cs index 92cec28..f37f322 100644 --- a/Services/ResourceGroupsClasses.cs +++ b/Services/ResourceGroupsClasses.cs @@ -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 { @@ -14,5 +20,14 @@ public class AzureResource public string? Type { get; set; } public string? Location { get; set; } public Dictionary? Tags { get; set; } + public string? Url + { + get + { + string[] parts = Type?.Split('/') ?? new string[0]; + return $"/images/{parts[0]}/{parts[1]}.svg"; + + } + } } } diff --git a/Views/ResourceGroups/Details.cshtml b/Views/ResourceGroups/Details.cshtml index 6970e75..9245a45 100644 --- a/Views/ResourceGroups/Details.cshtml +++ b/Views/ResourceGroups/Details.cshtml @@ -5,6 +5,6 @@
    @foreach (var resource in Model) { -
  • @resource.Name (@resource.Type)
  • +
  • @resource.Name
  • }
\ No newline at end of file diff --git a/Views/ResourceGroups/ManagementGroups.cshtml b/Views/ResourceGroups/ManagementGroups.cshtml new file mode 100644 index 0000000..fb93df6 --- /dev/null +++ b/Views/ResourceGroups/ManagementGroups.cshtml @@ -0,0 +1,10 @@ +@model List + +

Management groups:

+ +
    + @foreach (var group in Model) + { +
  • @group.Name (@group.Type / @group.Id)
  • + } +
\ No newline at end of file diff --git a/appsettings.json b/appsettings.json index 435c5d1..28ee4c0 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,10 +1,8 @@ { - "AzureAd": { - "ClientId": "", - "ClientSecret": "", - "TenantId": "", - "SubscriptionId": "" - }, + "ClientId": "", + "ClientSecret": "", + "TenantId": "", + "SubscriptionId": "", "Logging": { "LogLevel": { "Default": "Information", @@ -12,4 +10,4 @@ } }, "AllowedHosts": "*" -} \ No newline at end of file +} diff --git a/wwwroot/images/microsoft.cognitiveservices/accounts.svg b/wwwroot/images/microsoft.cognitiveservices/accounts.svg new file mode 100644 index 0000000..3c47ed9 --- /dev/null +++ b/wwwroot/images/microsoft.cognitiveservices/accounts.svg @@ -0,0 +1 @@ +Icon-machinelearning-162 \ No newline at end of file diff --git a/wwwroot/images/microsoft.compute/disks.svg b/wwwroot/images/microsoft.compute/disks.svg new file mode 100644 index 0000000..519c968 --- /dev/null +++ b/wwwroot/images/microsoft.compute/disks.svg @@ -0,0 +1 @@ +Icon-compute-32 \ No newline at end of file diff --git a/wwwroot/images/microsoft.insights/components.svg b/wwwroot/images/microsoft.insights/components.svg new file mode 100644 index 0000000..19f3e69 --- /dev/null +++ b/wwwroot/images/microsoft.insights/components.svg @@ -0,0 +1 @@ +Icon-manage-310 \ No newline at end of file diff --git a/wwwroot/images/microsoft.managedidentity/userassignedidentities.svg b/wwwroot/images/microsoft.managedidentity/userassignedidentities.svg new file mode 100644 index 0000000..a7450d7 --- /dev/null +++ b/wwwroot/images/microsoft.managedidentity/userassignedidentities.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wwwroot/images/microsoft.storage/storageaccounts.svg b/wwwroot/images/microsoft.storage/storageaccounts.svg new file mode 100644 index 0000000..e2a26a2 --- /dev/null +++ b/wwwroot/images/microsoft.storage/storageaccounts.svg @@ -0,0 +1 @@ +Icon-storage-86 \ No newline at end of file