Skip to content

Commit a4c9694

Browse files
adjusting app settings load (#15)
1 parent 6d37dce commit a4c9694

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/Program.cs

Lines changed: 6 additions & 3 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-
// 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);
7+
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
8+
// Load the configuration being supplicated by the cluster first
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/debugClient/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ namespace PayloadApp.DebugClient;
33
public class Program {
44
public static void Main(string[] args) {
55
var builder = WebApplication.CreateBuilder(args);
6-
6+
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
77
// 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);
8+
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);
99

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

1313
// 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);
14+
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
15+
if (!string.IsNullOrWhiteSpace(dotnet_env))
16+
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);
1517

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

test/integrationTests/TestSharedContext.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ public TestSharedContext() {
2525

2626
var builder = WebApplication.CreateBuilder();
2727

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

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

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

3740

3841
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))

0 commit comments

Comments
 (0)