Skip to content

Add support for Postgres trust host auth method with Docker Compose #41511

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

Conversation

theodorosidmar
Copy link
Contributor

Fixes #41509

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 16, 2024
@wilkinsona wilkinsona changed the title Add support for Postgres trust auth method at docker compose Add support for Postgres trust auth method with Docker Compose Jul 16, 2024
@wilkinsona wilkinsona changed the title Add support for Postgres trust auth method with Docker Compose Add support for Postgres trust host auth method with Docker Compose Jul 16, 2024
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @theodorosidmar. I've left a few comments for your consideration.

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 postgresAuthMethod = env.getOrDefault("POSTGRES_HOST_AUTH_METHOD", "password");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a default is needed here so this could just use get.

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 postgresAuthMethod = env.getOrDefault("POSTGRES_HOST_AUTH_METHOD", "password");
return Objects.equals(postgresAuthMethod, "trust");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really use Objects.equals. This could be return "trust".equals(postgresAuthMethod); instead.

@@ -78,6 +78,12 @@ void getPasswordWhenHasPostgresqlPassword() {
assertThat(environment.getPassword()).isEqualTo("secret");
}

@Test
void getPasswordWhenHasTrustAuthMethod() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPasswordWhenHasTrustHostAuthMethod()

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 postgresAuthMethod = env.getOrDefault("POSTGRES_HOST_AUTH_METHOD", "password");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I'd rename postgresAuthMethod to hostAuthMethod.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jul 16, 2024
@theodorosidmar theodorosidmar force-pushed the docker-compose-postgres-auth-method branch from a0000fd to 8e9a482 Compare July 16, 2024 12:16
@theodorosidmar
Copy link
Contributor Author

Awesome. Thank you for the review. Here you go: 8e9a482

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 16, 2024
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jul 16, 2024
@wilkinsona wilkinsona added this to the 3.4.x milestone Jul 16, 2024
@wilkinsona wilkinsona self-assigned this Jul 16, 2024
@wilkinsona
Copy link
Member

Thanks very much, @theodorosidmar, and congratulations on making your first contribution to Spring Boot.

@theodorosidmar
Copy link
Contributor Author

I should be thanking you. Thank you for your attention. Glad to contribute.

@theodorosidmar theodorosidmar deleted the docker-compose-postgres-auth-method branch July 16, 2024 18:49
@mshima
Copy link

mshima commented Sep 12, 2024

@wilkinsona can this PR be backported to 3.3.x?

@wilkinsona
Copy link
Member

I'm afraid not. We don't backport enhancements to maintenance branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spring-boot-docker-compose does not support POSTGRES_HOST_AUTH_METHOD
5 participants