Skip to content

Remove logic to obtain PostgreSQL password from environment variable #1353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Examples/DatabasePerTenantExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ private string GetConnectionString()
throw GetErrorForInvalidTenant(tenantName);
}

string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
return connectionString.Replace("###", postgresPassword);
return connectionString;
}

private string? GetTenantName()
Expand Down
6 changes: 3 additions & 3 deletions src/Examples/DatabasePerTenantExample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=DefaultTenantDb;User ID=postgres;Password=###;Include Error Detail=true",
"AdventureWorks": "Host=localhost;Database=AdventureWorks;User ID=postgres;Password=###;Include Error Detail=true",
"Contoso": "Host=localhost;Database=Contoso;User ID=postgres;Password=###;Include Error Detail=true"
"Default": "Host=localhost;Database=DefaultTenantDb;User ID=postgres;Password=postgres;Include Error Detail=true",
"AdventureWorks": "Host=localhost;Database=AdventureWorks;User ID=postgres;Password=postgres;Include Error Detail=true",
"Contoso": "Host=localhost;Database=Contoso;User ID=postgres;Password=postgres;Include Error Detail=true"
},
"Logging": {
"LogLevel": {
Expand Down
8 changes: 1 addition & 7 deletions src/Examples/JsonApiDotNetCoreExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void ConfigureServices(WebApplicationBuilder builder)

builder.Services.AddDbContext<AppDbContext>(options =>
{
string? connectionString = GetConnectionString(builder.Configuration);
string? connectionString = builder.Configuration.GetConnectionString("Default");
options.UseNpgsql(connectionString);

SetDbContextDebugOptions(options);
Expand All @@ -73,12 +73,6 @@ static void ConfigureServices(WebApplicationBuilder builder)
}
}

static string? GetConnectionString(IConfiguration configuration)
{
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
return configuration.GetConnectionString("Default")?.Replace("###", postgresPassword);
}

[Conditional("DEBUG")]
static void SetDbContextDebugOptions(DbContextOptionsBuilder options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=###;Include Error Detail=true"
"Default": "Host=localhost;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres;Include Error Detail=true"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext<TestableStartup<
services.AddResourceRepository<MusicTrackRepository>();
services.AddResourceRepository<LyricRepository>();

string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";

string dbConnectionString =
$"Host=localhost;Database=JsonApiTest-Extra-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword};Include Error Detail=true";
$"Host=localhost;Database=JsonApiTest-Extra-{Guid.NewGuid():N};User ID=postgres;Password=postgres;Include Error Detail=true";

services.AddDbContext<ExtraDbContext>(options => options.UseNpgsql(dbConnectionString));
});
Expand Down
5 changes: 1 addition & 4 deletions test/TestBuildingBlocks/IntegrationTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ protected override HttpClient CreateClient()

private WebApplicationFactory<TStartup> CreateFactory()
{
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";

string dbConnectionString =
$"Host=localhost;Database=JsonApiTest-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword};Include Error Detail=true";
string dbConnectionString = $"Host=localhost;Database=JsonApiTest-{Guid.NewGuid():N};User ID=postgres;Password=postgres;Include Error Detail=true";

var factory = new IntegrationTestWebApplicationFactory();

Expand Down