Skip to content

Commit

Permalink
Add sslMode option lowercase alias
Browse files Browse the repository at this point in the history
For easier JDBC URL adaption

[resolves #486]
  • Loading branch information
Sergey Starosek authored and mp911de committed Apr 6, 2022
1 parent df270f2 commit 8018584
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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

0 comments on commit 8018584

Please sign in to comment.