From 1bd14501ca5da5d123064b504562c6ddb3305e4c Mon Sep 17 00:00:00 2001 From: Ryan Campbell <89273172+bigtallcampbell@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:12:35 -0500 Subject: [PATCH] adjusting app settings load (#14) --- src/Program.cs | 7 +++++-- test/debugClient/Program.cs | 7 +++++-- test/integrationTests/TestSharedContext.cs | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index e03a126..3652edb 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -4,14 +4,17 @@ public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); + string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set"); // Load the configuration being supplicated by the cluster first - builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false); + builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values - builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false); + string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); + if (!string.IsNullOrWhiteSpace(dotnet_env)) + builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false); builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2)) .ConfigureServices((services) => { diff --git a/test/debugClient/Program.cs b/test/debugClient/Program.cs index 8c49188..21566ac 100644 --- a/test/debugClient/Program.cs +++ b/test/debugClient/Program.cs @@ -4,14 +4,17 @@ public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); + string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set"); // Load the configuration being supplicated by the cluster first - builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false); + builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values - builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false); + string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); + if (!string.IsNullOrWhiteSpace(dotnet_env)) + builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false); builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2)) .ConfigureServices((services) => { diff --git a/test/integrationTests/TestSharedContext.cs b/test/integrationTests/TestSharedContext.cs index a29d309..2cb4d82 100644 --- a/test/integrationTests/TestSharedContext.cs +++ b/test/integrationTests/TestSharedContext.cs @@ -24,14 +24,17 @@ public TestSharedContext() { if (_grpcHost != null) return; var builder = WebApplication.CreateBuilder(); + string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set"); // Load the configuration being supplicated by the cluster first - builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false); + builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false); // Load any local appsettings incase they're overriding the cluster values - builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false); + string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); + if (!string.IsNullOrWhiteSpace(dotnet_env)) + builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false); builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2)) .ConfigureServices((services) => {