Removed app protected settings.
This commit is contained in:
parent
a2750a154c
commit
e3e26392b6
6
.gitignore
vendored
6
.gitignore
vendored
@ -27,6 +27,10 @@ Project_Readme.html
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
.idea/
|
||||
.mono/
|
||||
|
||||
# secret folder '.secrets' all over the project git controlled
|
||||
.secrets/
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
@ -226,6 +230,8 @@ Thumbs.db
|
||||
.idea/
|
||||
|
||||
# custom
|
||||
# Ignore environment-specific appsettings, but allow .example files
|
||||
/**/**/appsettings.*.json
|
||||
!/**/**/appsettings.*.json.example
|
||||
|
||||
**/**/deployment.yml
|
||||
|
||||
@ -7,14 +7,26 @@ public class HostBuilderFactory<TStartup> where TStartup : class
|
||||
public IHostBuilder CreateHostBuilder(string[] args, string? baseDirectory = null)
|
||||
{
|
||||
var builder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((_, configurationBuilder) =>
|
||||
.ConfigureWebHostDefaults(host => { host.UseStartup<TStartup>(); })
|
||||
.ConfigureAppConfiguration((context, configurationBuilder) =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(baseDirectory))
|
||||
configurationBuilder.SetBasePath(baseDirectory);
|
||||
|
||||
configurationBuilder.AddJsonFile("appsettings.protected.json", optional: true);
|
||||
// Configuration priority (low to high):
|
||||
// 1. appsettings.json (already loaded by CreateDefaultBuilder)
|
||||
// 2. appsettings.{Environment}.json (already loaded)
|
||||
// 3. User Secrets (already loaded in Development)
|
||||
// 4. Environment Variables (already loaded) ← highest priority
|
||||
|
||||
// Debug mode: log configuration on startup
|
||||
if (Environment.GetEnvironmentVariable("NOCR_DEBUG_MODE") == "true")
|
||||
{
|
||||
Console.WriteLine("[NOCR_DEBUG] Configuration debug mode enabled");
|
||||
Console.WriteLine($"[NOCR_DEBUG] Environment: {context.HostingEnvironment.EnvironmentName}");
|
||||
Console.WriteLine($"[NOCR_DEBUG] Base Path: {baseDirectory ?? configurationBuilder.Build().GetValue<string>("ContentRoot") ?? "default"}");
|
||||
}
|
||||
})
|
||||
.ConfigureWebHostDefaults(host => { host.UseStartup<TStartup>(); })
|
||||
.UseSerilog((ctx, logBuilder) =>
|
||||
{
|
||||
logBuilder.ReadFrom.Configuration(ctx.Configuration)
|
||||
|
||||
@ -15,6 +15,12 @@ public class Startup
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Debug mode: log loaded configuration
|
||||
if (Environment.GetEnvironmentVariable("NOCR_DEBUG_MODE") == "true")
|
||||
{
|
||||
LogConfigurationDebug();
|
||||
}
|
||||
|
||||
services.AddSingleton<ICurrentDateProvider, DefaultCurrentDateProvider>();
|
||||
|
||||
services.AddControllers();
|
||||
@ -40,4 +46,22 @@ public class Startup
|
||||
app.UseHealthChecks("/health");
|
||||
app.UseEndpoints(builder => builder.MapControllers());
|
||||
}
|
||||
|
||||
private void LogConfigurationDebug()
|
||||
{
|
||||
Console.WriteLine("=== [NOCR_DEBUG] Configuration Values ===");
|
||||
|
||||
var connString = Configuration.GetConnectionString(nameof(UsersContext));
|
||||
Console.WriteLine($"[NOCR_DEBUG] UsersContext ConnectionString: {MaskConnectionString(connString)}");
|
||||
|
||||
Console.WriteLine("=== [NOCR_DEBUG] End Configuration ===");
|
||||
}
|
||||
|
||||
private static string MaskConnectionString(string? value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return "(empty)";
|
||||
// Mask password in connection string
|
||||
var masked = System.Text.RegularExpressions.Regex.Replace(value, @"(?i)(password|pwd)=([^;]+)", m => $"{m.Groups[1].Value}=***");
|
||||
return masked;
|
||||
}
|
||||
}
|
||||
9
src/Nocr.Users.Host/appsettings.Development.json.example
Normal file
9
src/Nocr.Users.Host/appsettings.Development.json.example
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
// This file provides an example configuration for local VS Code debugging.
|
||||
// Copy this file to appsettings.Development.json and fill in your actual values.
|
||||
|
||||
"ConnectionStrings": {
|
||||
// MariaDB connection string for Users database
|
||||
"UsersContext": "server=localhost;port=3326;database=nocr_users;uid=root;pwd=toor"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
// This file provides an example configuration for Docker Compose deployment.
|
||||
// Copy this file to appsettings.DockerCompose.json.
|
||||
|
||||
"ConnectionStrings": {
|
||||
// MariaDB connection - use service name from docker-compose.yml
|
||||
"UsersContext": "server=nocr-users-db;port=3306;database=nocr_users;uid=root;pwd=toor"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user