Skip to content

Commit eea74e3

Browse files
committed
Move the startup message to enable usage when trying SSL modes
1 parent 0caafab commit eea74e3

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionFactory.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,8 @@ protected Future<Connection> doConnectInternal(PgConnectOptions options, Context
7070
} catch (Exception e) {
7171
return context.failedFuture(e);
7272
}
73-
String username = options.getUser();
74-
String password = options.getPassword();
75-
String database = options.getDatabase();
7673
SocketAddress server = options.getSocketAddress();
77-
Map<String, String> properties = options.getProperties() != null ? Collections.unmodifiableMap(options.getProperties()) : null;
78-
return doConnect(server, context, options).flatMap(conn -> {
79-
PgSocketConnection socket = (PgSocketConnection) conn;
80-
socket.init();
81-
return Future.<Connection>future(p -> socket.sendStartupMessage(username, password, database, properties, p))
82-
.map(conn);
83-
});
74+
return doConnect(server, context, options);
8475
}
8576

8677
public void cancelRequest(PgConnectOptions options, int processId, int secretKey, Handler<AsyncResult<Void>> handler) {
@@ -121,6 +112,19 @@ private Future<Connection> doConnect(SocketAddress server, ContextInternal conte
121112
}
122113

123114
private Future<Connection> doConnect(ConnectOptions connectOptions, ContextInternal context, boolean ssl, PgConnectOptions options) {
115+
return doConnect_(connectOptions, context, ssl, options).flatMap(conn -> {
116+
String username = options.getUser();
117+
String password = options.getPassword();
118+
String database = options.getDatabase();
119+
Map<String, String> properties = options.getProperties() != null ? Collections.unmodifiableMap(options.getProperties()) : null;
120+
PgSocketConnection socket = (PgSocketConnection) conn;
121+
socket.init();
122+
return Future.<Connection>future(p -> socket.sendStartupMessage(username, password, database, properties, p))
123+
.map(conn);
124+
});
125+
}
126+
127+
private Future<Connection> doConnect_(ConnectOptions connectOptions, ContextInternal context, boolean ssl, PgConnectOptions options) {
124128
Future<NetSocket> soFut;
125129
try {
126130
soFut = client.connect(connectOptions);

vertx-pg-client/src/test/java/io/vertx/pgclient/junit/ContainerPgRule.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ private void initServer(String version) throws Exception {
8181
.withClasspathResourceMapping("tls/server.crt", "/server.crt", BindMode.READ_ONLY)
8282
.withClasspathResourceMapping("tls/server.key", "/server.key", BindMode.READ_ONLY)
8383
.withClasspathResourceMapping("tls/ssl.sh", "/docker-entrypoint-initdb.d/ssl.sh", BindMode.READ_ONLY);
84-
if (forceSsl) {
85-
server
86-
.withClasspathResourceMapping("tls/pg_hba.conf", "/tmp/pg_hba.conf", BindMode.READ_ONLY)
87-
.withClasspathResourceMapping("tls/force_ssl.sh", "/docker-entrypoint-initdb.d/force_ssl.sh", BindMode.READ_ONLY);
88-
89-
}
84+
if (forceSsl) {
85+
server
86+
.withClasspathResourceMapping("tls/pg_hba.conf", "/tmp/pg_hba.conf", BindMode.READ_ONLY)
87+
.withClasspathResourceMapping("tls/force_ssl.sh", "/docker-entrypoint-initdb.d/force_ssl.sh", BindMode.READ_ONLY);
88+
}
9089
}
9190
if (System.getProperties().containsKey("containerFixedPort")) {
9291
server.withFixedExposedPort(POSTGRESQL_PORT, POSTGRESQL_PORT);

0 commit comments

Comments
 (0)