Skip to content

Commit 5835f02

Browse files
authored
Merge pull request #1353 from json-api-dotnet/drop-postgres-pwd-env-var
Remove logic to obtain PostgreSQL password from environment variable
2 parents 050a33d + dbfc35d commit 5835f02

File tree

6 files changed

+8
-20
lines changed

6 files changed

+8
-20
lines changed

src/Examples/DatabasePerTenantExample/Data/AppDbContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ private string GetConnectionString()
4444
throw GetErrorForInvalidTenant(tenantName);
4545
}
4646

47-
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
48-
return connectionString.Replace("###", postgresPassword);
47+
return connectionString;
4948
}
5049

5150
private string? GetTenantName()

src/Examples/DatabasePerTenantExample/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"ConnectionStrings": {
3-
"Default": "Host=localhost;Database=DefaultTenantDb;User ID=postgres;Password=###;Include Error Detail=true",
4-
"AdventureWorks": "Host=localhost;Database=AdventureWorks;User ID=postgres;Password=###;Include Error Detail=true",
5-
"Contoso": "Host=localhost;Database=Contoso;User ID=postgres;Password=###;Include Error Detail=true"
3+
"Default": "Host=localhost;Database=DefaultTenantDb;User ID=postgres;Password=postgres;Include Error Detail=true",
4+
"AdventureWorks": "Host=localhost;Database=AdventureWorks;User ID=postgres;Password=postgres;Include Error Detail=true",
5+
"Contoso": "Host=localhost;Database=Contoso;User ID=postgres;Password=postgres;Include Error Detail=true"
66
},
77
"Logging": {
88
"LogLevel": {

src/Examples/JsonApiDotNetCoreExample/Program.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void ConfigureServices(WebApplicationBuilder builder)
4949

5050
builder.Services.AddDbContext<AppDbContext>(options =>
5151
{
52-
string? connectionString = GetConnectionString(builder.Configuration);
52+
string? connectionString = builder.Configuration.GetConnectionString("Default");
5353
options.UseNpgsql(connectionString);
5454

5555
SetDbContextDebugOptions(options);
@@ -73,12 +73,6 @@ static void ConfigureServices(WebApplicationBuilder builder)
7373
}
7474
}
7575

76-
static string? GetConnectionString(IConfiguration configuration)
77-
{
78-
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
79-
return configuration.GetConnectionString("Default")?.Replace("###", postgresPassword);
80-
}
81-
8276
[Conditional("DEBUG")]
8377
static void SetDbContextDebugOptions(DbContextOptionsBuilder options)
8478
{

src/Examples/JsonApiDotNetCoreExample/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ConnectionStrings": {
3-
"Default": "Host=localhost;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=###;Include Error Detail=true"
3+
"Default": "Host=localhost;Database=JsonApiDotNetCoreExample;User ID=postgres;Password=postgres;Include Error Detail=true"
44
},
55
"Logging": {
66
"LogLevel": {

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext<TestableStartup<
2727
services.AddResourceRepository<MusicTrackRepository>();
2828
services.AddResourceRepository<LyricRepository>();
2929

30-
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
31-
3230
string dbConnectionString =
33-
$"Host=localhost;Database=JsonApiTest-Extra-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword};Include Error Detail=true";
31+
$"Host=localhost;Database=JsonApiTest-Extra-{Guid.NewGuid():N};User ID=postgres;Password=postgres;Include Error Detail=true";
3432

3533
services.AddDbContext<ExtraDbContext>(options => options.UseNpgsql(dbConnectionString));
3634
});

test/TestBuildingBlocks/IntegrationTestContext.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ protected override HttpClient CreateClient()
6464

6565
private WebApplicationFactory<TStartup> CreateFactory()
6666
{
67-
string postgresPassword = Environment.GetEnvironmentVariable("PGPASSWORD") ?? "postgres";
68-
69-
string dbConnectionString =
70-
$"Host=localhost;Database=JsonApiTest-{Guid.NewGuid():N};User ID=postgres;Password={postgresPassword};Include Error Detail=true";
67+
string dbConnectionString = $"Host=localhost;Database=JsonApiTest-{Guid.NewGuid():N};User ID=postgres;Password=postgres;Include Error Detail=true";
7168

7269
var factory = new IntegrationTestWebApplicationFactory();
7370

0 commit comments

Comments
 (0)