Add support for Postgres trust host auth method with Docker Compose
See gh-41511
This commit is contained in:
@@ -28,6 +28,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @author Sidmar Theodoro
|
||||
*/
|
||||
class PostgresEnvironment {
|
||||
|
||||
@@ -44,11 +45,19 @@ class PostgresEnvironment {
|
||||
}
|
||||
|
||||
private String extractPassword(Map<String, String> env) {
|
||||
if (hasTrustAuthMethod(env)) {
|
||||
return null;
|
||||
}
|
||||
String password = env.getOrDefault("POSTGRES_PASSWORD", env.get("POSTGRESQL_PASSWORD"));
|
||||
Assert.state(StringUtils.hasLength(password), "PostgreSQL password must be provided");
|
||||
return password;
|
||||
}
|
||||
|
||||
private Boolean hasTrustAuthMethod(Map<String, String> env) {
|
||||
String hostAuthMethod = env.get("POSTGRES_HOST_AUTH_METHOD");
|
||||
return "trust".equals(hostAuthMethod);
|
||||
}
|
||||
|
||||
String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,12 @@ class PostgresEnvironmentTests {
|
||||
assertThat(environment.getPassword()).isEqualTo("secret");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPasswordWhenHasTrustHostAuthMethod() {
|
||||
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_HOST_AUTH_METHOD", "trust"));
|
||||
assertThat(environment.getPassword()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDatabaseWhenNoPostgresDbOrPostgresUser() {
|
||||
PostgresEnvironment environment = new PostgresEnvironment(Map.of("POSTGRES_PASSWORD", "secret"));
|
||||
|
||||
Reference in New Issue
Block a user