From a099b77bf429ea213670ee9166092a66182f1463 Mon Sep 17 00:00:00 2001 From: robbwilcox Date: Mon, 14 Oct 2024 15:57:55 -0500 Subject: [PATCH] revert --- BackgroundService/BackgroundService.cs | 1 + Program.cs | 64 ++++++++------------------ Sentinel.sln | 25 ++++++++++ appsettings.json | 39 ++++++++-------- 4 files changed, 65 insertions(+), 64 deletions(-) create mode 100644 Sentinel.sln diff --git a/BackgroundService/BackgroundService.cs b/BackgroundService/BackgroundService.cs index 59d7254..88f5653 100644 --- a/BackgroundService/BackgroundService.cs +++ b/BackgroundService/BackgroundService.cs @@ -81,6 +81,7 @@ public class RoleAssesorBackgroundService : IHostedService, IDisposable public void Dispose() { + GC.SuppressFinalize(this); _timer?.Dispose(); } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 6e778f6..3f31437 100644 --- a/Program.cs +++ b/Program.cs @@ -2,55 +2,29 @@ using Microsoft.Extensions.Azure; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Configuration; using ProperDI.Azure.Endpoints.ResourceGroup; -public class Program +HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); + +builder.Services.AddHttpClient(); +builder.Services.AddTransient(); +builder.Services.AddAzureClients(clientBuilder => { - public static async Task Main(string[] args) + // var creds = new ClientSecretCredential( + // "", + // "", + // ""); + clientBuilder.UseCredential(new DefaultAzureCredential()); + clientBuilder.AddArmClient(builder.Configuration.GetSection("Am95DevSubscriptionId")); + clientBuilder.ConfigureDefaults(client => { - var host = CreateHostBuilder(args).Build(); - await host.RunAsync(); - } + client.Retry.MaxRetries = 3; + }); +}); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((hostingContext, config) => - { - config.AddEnvironmentVariables(); - - // Optionally, you can add JSON configuration if needed - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); - // config.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true); - }) - .ConfigureServices((hostContext, services) => - { - services.AddHttpClient(); - services.AddTransient(); +builder.Services.Configure(builder.Configuration.GetSection("RoleAssessorBackgroundService")); +builder.Services.AddHostedService(); - services.AddAzureClients(clientBuilder => - { - var configuration = hostContext.Configuration; - - // Read Azure credentials from environment variables - var tenantId = configuration["AzureTenantId"]; - var clientId = configuration["AzureClientId"]; - var clientSecret = configuration["AzureClientSecret"]; - var subscriptionId = configuration["AzureSubscriptionId"]; - System.Console.WriteLine($"Tenant id: {tenantId}\nClientID: {clientId}\nClientSecret: {clientSecret}"); - var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); +var host = builder.Build(); - clientBuilder.UseCredential(credential); - clientBuilder.AddArmClient(subscriptionId); - clientBuilder.ConfigureDefaults(client => - { - client.Retry.MaxRetries = 3; - }); - clientBuilder.AddLogsQueryClient(); - }); - - services.Configure( - hostContext.Configuration.GetSection("RoleAssessorBackgroundService")); - services.AddHostedService(); - }); -} \ No newline at end of file +await host.RunAsync(); \ No newline at end of file diff --git a/Sentinel.sln b/Sentinel.sln new file mode 100644 index 0000000..d605110 --- /dev/null +++ b/Sentinel.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentinel", "Sentinel.csproj", "{FA937A3C-5191-4DAC-AC62-EBF7EE90BD1F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA937A3C-5191-4DAC-AC62-EBF7EE90BD1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA937A3C-5191-4DAC-AC62-EBF7EE90BD1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA937A3C-5191-4DAC-AC62-EBF7EE90BD1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA937A3C-5191-4DAC-AC62-EBF7EE90BD1F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {79EE9B52-D46E-4FBB-8310-32FD5835CF1D} + EndGlobalSection +EndGlobal diff --git a/appsettings.json b/appsettings.json index fb0de21..9d12da1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,21 +1,22 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information", - "System.Net": "Warning", - "Azure.Core": "Warning", - "Azure.Identity": "Warning" - } - }, - "RoleAssessorBackgroundService": { - "RunFrequencyInMinutes": 12 - }, - "DefaultSubscriptionId": "2690a5f1-155b-4fa8-896f-92c6bcb62bee", - "ASPNETCORE_ENVIRONMENT": "Development", - "AzureSubscriptionId": "2690a5f1-155b-4fa8-896f-92c6bcb62bee", - "AzureTenantId": "11ffe5d3-5e72-4414-8dfd-1eb209497679", - "AzureClientId": "d0870778-24dd-4c87-a449-2c36674035d1", - "AzureClientSecret": "EWX8Q~jpfKab8hB1TzujorzKIeJEV5NKEfCuOaFC" + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information", + "System.Net": "Warning", + "Azure.Core": "Warning", + "Azure.Identity": "Warning" + } + }, + "RoleAssessorBackgroundService": { + "RunFrequencyInMinutes": 12 + }, + "Am95DevSubscriptionId": "040698c2-a013-45be-b1fa-e975f46b9d63", + "DefaultSubscriptionId": "2690a5f1-155b-4fa8-896f-92c6bcb62bee", + "ASPNETCORE_ENVIRONMENT": "Development", + "AzureSubscriptionId": "2690a5f1-155b-4fa8-896f-92c6bcb62bee", + "AzureTenantId": "11ffe5d3-5e72-4414-8dfd-1eb209497679", + "AzureClientId": "d0870778-24dd-4c87-a449-2c36674035d1", + "AzureClientSecret": "EWX8Q~jpfKab8hB1TzujorzKIeJEV5NKEfCuOaFC" } \ No newline at end of file