Skip to content
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

Add sslMode option lowercase alias #504

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public final class PostgresqlConnectionFactoryProvider implements ConnectionFact
*/
public static final Option<SSLMode> SSL_MODE = Option.valueOf("sslMode");

/**
* Ssl mode alias (JDBC style). Default: disabled
*/
public static final Option<SSLMode> SSL_MODE_ALIAS = Option.valueOf("sslmode");

/**
* SSL key password
*/
Expand Down Expand Up @@ -301,7 +306,18 @@ private static void setupSsl(PostgresqlConnectionConfiguration.Builder builder,

return (SSLMode) it;

}).to(builder::sslMode);
}).to(builder::sslMode).otherwise(() -> {

mapper.from(SSL_MODE_ALIAS).map(it -> {

if (it instanceof String) {
return SSLMode.fromValue(it.toString());
}

return (SSLMode) it;

}).to(builder::sslMode);
});

mapper.fromTyped(SSL_CERT).to(builder::sslCert);
mapper.fromTyped(SSL_CONTEXT_BUILDER_CUSTOMIZER).to(builder::sslContextBuilderCustomizer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ void supportsSslMode() {
assertThat(sslConfig.getSslMode()).isEqualTo(SSLMode.DISABLE);
}

@Test
void supportsSslModeAlias() {
PostgresqlConnectionFactory factory = this.provider.create(builder()
.option(DRIVER, POSTGRESQL_DRIVER)
.option(HOST, "test-host")
.option(PASSWORD, "test-password")
.option(USER, "test-user")
.option(Option.valueOf("sslmode"), "require")
.build());

SSLConfig sslConfig = factory.getConfiguration().getSslConfig();

assertThat(sslConfig.getSslMode()).isEqualTo(SSLMode.REQUIRE);
}

@Test
void shouldCreateConnectionFactoryWithoutPassword() {
assertThat(this.provider.create(ConnectionFactoryOptions.builder()
Expand Down