Skip to content

Commit c38a4d3

Browse files
committed
Change AuthPassthrough::fetch_hah to use Address username
1 parent 44656fa commit c38a4d3

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/auth_passthrough.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,28 @@ impl AuthPassthrough {
5454
None
5555
}
5656

57-
/// Connects to server and executes auth_query for the specidief user.
58-
/// If the response is a row with two columns containing the user
59-
/// and its MD5 hash, the hash returned.
57+
/// Connects to server and executes auth_query for the specified address.
58+
/// If the response is a row with two columns containing the username set in the address.
59+
/// and its MD5 hash, the MD5 hash returned.
6060
///
6161
/// Note that the query is executed, changing $1 with the name of the user
6262
/// this is so we only hold in memory (and transfer) the least amount of 'sensitive' data.
6363
/// Also, it is compatible with pgbouncer.
6464
///
6565
/// # Arguments
6666
///
67-
/// * `address` - An Address of the server we want to connect to.
68-
/// * `user` - A user that will be used to obtain the hash.
67+
/// * `address` - An Address of the server we want to connect to. The username for the hash will be obtained from this value.
6968
///
7069
/// # Examples
7170
///
7271
/// ```
7372
/// use pgcat::auth_passthrough::AuthPassthrough;
7473
/// use pgcat::config::Address;
7574
/// let auth_passthrough = AuthPassthrough::new("SELECT * FROM public.user_lookup('$1');", "postgres", "postgres", "postgres");
76-
/// auth_passthrough.fetch_hash(&Address::default(), "foo");
75+
/// auth_passthrough.fetch_hash(&Address::default());
7776
/// ```
7877
///
79-
pub async fn fetch_hash(
80-
&self,
81-
address: &crate::config::Address,
82-
user: &str,
83-
) -> Result<String, Error> {
78+
pub async fn fetch_hash(&self, address: &crate::config::Address) -> Result<String, Error> {
8479
let auth_user = crate::config::User {
8580
username: self.user.clone(),
8681
password: Some(self.password.clone()),
@@ -89,6 +84,7 @@ impl AuthPassthrough {
8984
};
9085

9186
let client_server_map: ClientServerMap = Arc::new(Mutex::new(HashMap::new()));
87+
let user = &address.username;
9288

9389
debug!("Connecting to server to obtain auth hashes.");
9490
match Server::startup(

src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl ConnectionPool {
234234
// TODO: Make it server dependant.
235235
let mut auth_hash = None;
236236
if let Some(apt) = auth_passthrough.as_ref() {
237-
match apt.fetch_hash(&address, &user.username).await {
237+
match apt.fetch_hash(&address).await {
238238
Ok(ok) => {
239239
if let Some(pool_auth_hash_value) = pool_auth_hash {
240240
if ok != pool_auth_hash_value {

0 commit comments

Comments
 (0)