Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
[#486][resolves #504]

Signed-off-by: Mark Paluch <mpaluch@vmware.com>
  • Loading branch information
mp911de committed Apr 6, 2022
1 parent 8018584 commit 1409604
Showing 1 changed file with 12 additions and 19 deletions.
Expand Up @@ -182,6 +182,8 @@ public final class PostgresqlConnectionFactoryProvider implements ConnectionFact

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

Expand Down Expand Up @@ -298,25 +300,8 @@ private static void setupSsl(PostgresqlConnectionConfiguration.Builder builder,
}
});

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

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

return (SSLMode) it;

}).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.from(SSL_MODE).map(PostgresqlConnectionFactoryProvider::toSSLMode).to(builder::sslMode).otherwise(() -> {
mapper.from(SSL_MODE_ALIAS).map(PostgresqlConnectionFactoryProvider::toSSLMode).to(builder::sslMode);
});

mapper.fromTyped(SSL_CERT).to(builder::sslCert);
Expand All @@ -343,6 +328,14 @@ private static void setupSsl(PostgresqlConnectionConfiguration.Builder builder,
}).to(builder::sslHostnameVerifier);
}

private static SSLMode toSSLMode(Object it) {
if (it instanceof String) {
return SSLMode.fromValue(it.toString());
}

return (SSLMode) it;
}

@SuppressWarnings("unchecked")
private static Map<String, String> convertToMap(Object options) {
if (options instanceof Map) {
Expand Down

0 comments on commit 1409604

Please sign in to comment.