Skip to content

Commit af89924

Browse files
theodorosidmarwilkinsona
authored andcommitted
Add support for Postgres trust host auth method with Docker Compose
See gh-41511
1 parent d2cd5c9 commit af89924

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @author Andy Wilkinson
2929
* @author Phillip Webb
3030
* @author Scott Frederick
31+
* @author Sidmar Theodoro
3132
*/
3233
class PostgresEnvironment {
3334

@@ -44,11 +45,19 @@ class PostgresEnvironment {
4445
}
4546

4647
private String extractPassword(Map<String, String> env) {
48+
if (hasTrustAuthMethod(env)) {
49+
return null;
50+
}
4751
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
4852
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
4953
return password;
5054
}
5155

56+
private Boolean hasTrustAuthMethod(Map<String, String> env) {
57+
String hostAuthMethod = env.get("POSTGRES_HOST_AUTH_METHOD");
58+
return "trust".equals(hostAuthMethod);
59+
}
60+
5261
String getUsername() {
5362
return this.username;
5463
}

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/postgres/PostgresEnvironmentTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ void getPasswordWhenHasPostgresqlPassword() {
7878
assertThat(environment.getPassword()).isEqualTo("secret");
7979
}
8080

81+
@Test
82+
void getPasswordWhenHasTrustHostAuthMethod() {
83+
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_HOST_AUTH_METHOD", "trust"));
84+
assertThat(environment.getPassword()).isNull();
85+
}
86+
8187
@Test
8288
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
8389
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));

0 commit comments

Comments
 (0)