Skip to content

Commit a78ad36

Browse files
updating appsettings load (#14)
1 parent 84103c7 commit a78ad36

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Program.cs

+5-2
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/debugClient/Program.cs

+5-2
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

+5-2
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)