Skip to content

Commit 062dcf6

Browse files
adjusting app settings load (#17)
1 parent e4ea89b commit 062dcf6

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ public class Program {
66
public static void Main(string[] args) {
77
var builder = WebApplication.CreateBuilder(args);
88

9+
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
910
// Load the configuration being supplicated by the cluster first
10-
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
11+
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);
1112

1213
// Load any local appsettings incase they're overriding the cluster values
1314
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);
1415

1516
// Load any local appsettings incase they're overriding the cluster values
16-
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
17+
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
18+
if (!string.IsNullOrWhiteSpace(dotnet_env))
19+
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);
1720

1821
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
1922
.ConfigureServices((services) => {

test/debugClient/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ public class Program {
44
public static void Main(string[] args) {
55
var builder = WebApplication.CreateBuilder(args);
66

7+
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
78
// Load the configuration being supplicated by the cluster first
8-
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
9+
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);
910

1011
// Load any local appsettings incase they're overriding the cluster values
1112
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);
1213

1314
// Load any local appsettings incase they're overriding the cluster values
14-
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
15+
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
16+
if (!string.IsNullOrWhiteSpace(dotnet_env))
17+
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);
1518

1619
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
1720
.ConfigureServices((services) => {

test/integrationTests/TestSharedContext.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ public TestSharedContext() {
2222
if (_grpcHost != null) return;
2323

2424
var builder = WebApplication.CreateBuilder();
25+
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
2526
// Load the configuration being supplicated by the cluster first
26-
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
27+
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);
2728

2829
// Load any local appsettings incase they're overriding the cluster values
2930
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);
3031

3132
// Load any local appsettings incase they're overriding the cluster values
32-
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
33+
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
34+
if (!string.IsNullOrWhiteSpace(dotnet_env))
35+
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);
3336

3437
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
3538
.ConfigureServices((services) => {

0 commit comments

Comments
 (0)