Skip to content

Commit 33db0df

Browse files
authored
stream.peer_addr() & auth_query (#575)
* Don't unwrap stream.peer_addr() #562 (same code) (another lines changed) * auth_query (real sample) # single quote need auth_query="SELECT usename, passwd FROM pg_shadow WHERE usename='$1'"
1 parent 7994a66 commit 33db0df

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pgcat.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ sharding_function = "pg_bigint_hash"
187187
# Query to be sent to servers to obtain the hash used for md5 authentication. The connection will be
188188
# established using the database configured in the pool. This parameter is inherited by every pool
189189
# and can be redefined in pool configuration.
190-
# auth_query = "SELECT $1"
190+
# auth_query="SELECT usename, passwd FROM pg_shadow WHERE usename='$1'"
191191

192192
# User to be used for connecting to servers to obtain the hash used for md5 authentication by sending the query
193193
# specified in `auth_query_user`. The connection will be established using the database configured in the pool.

src/client.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ pub async fn client_entrypoint(
117117
log_client_connections: bool,
118118
) -> Result<(), Error> {
119119
// Figure out if the client wants TLS or not.
120-
let addr = stream.peer_addr().unwrap();
120+
let addr = match stream.peer_addr() {
121+
Ok(addr) => addr,
122+
Err(err) => {
123+
return Err(Error::SocketError(format!(
124+
"Failed to get peer address: {:?}",
125+
err
126+
)));
127+
}
128+
};
121129

122130
match get_startup::<TcpStream>(&mut stream).await {
123131
// Client requested a TLS connection.

0 commit comments

Comments
 (0)