Skip to content

Commit fef737e

Browse files
committed
fmt
1 parent 345ee88 commit fef737e

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

src/auth.rs

+34-11
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
use crate::errors::Error;
66
use crate::tokio::io::AsyncReadExt;
77
use crate::{
8+
auth_passthrough::AuthPassthrough,
89
config::get_config,
9-
messages::{error_response, md5_hash_password, write_all, wrong_password, md5_hash_second_pass},
10+
messages::{
11+
error_response, md5_hash_password, md5_hash_second_pass, write_all, wrong_password,
12+
},
1013
pool::{get_pool, ConnectionPool},
11-
auth_passthrough::AuthPassthrough,
1214
};
1315
use bytes::{BufMut, BytesMut};
1416
use log::debug;
1517

16-
async fn refetch_auth_hash<S>(pool: &ConnectionPool, stream: &mut S, username: &str, pool_name: &str) -> Result<String, Error>
17-
where S: tokio::io::AsyncWrite + std::marker::Unpin + std::marker::Send
18+
async fn refetch_auth_hash<S>(
19+
pool: &ConnectionPool,
20+
stream: &mut S,
21+
username: &str,
22+
pool_name: &str,
23+
) -> Result<String, Error>
24+
where
25+
S: tokio::io::AsyncWrite + std::marker::Unpin + std::marker::Send,
1826
{
1927
let address = pool.address(0, 0);
2028
if let Some(apt) = AuthPassthrough::from_pool_settings(&pool.settings) {
@@ -29,7 +37,8 @@ where S: tokio::io::AsyncWrite + std::marker::Unpin + std::marker::Send
2937
"No password set and auth passthrough failed for database: {}, user: {}",
3038
pool_name, username
3139
),
32-
).await?;
40+
)
41+
.await?;
3342

3443
Err(Error::ClientError(format!(
3544
"Could not obtain hash for {{ username: {:?}, database: {:?} }}. Auth passthrough not enabled.",
@@ -174,8 +183,7 @@ impl ClearText {
174183
"Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}",
175184
self.username, self.pool_name, self.application_name
176185
)))
177-
}
178-
else {
186+
} else {
179187
validate_pool(write, pool, &self.username, &self.pool_name).await?;
180188

181189
Ok(None)
@@ -305,7 +313,7 @@ impl Md5 {
305313
Some(ref password) => {
306314
let our_hash = md5_hash_password(&self.username, password, &self.salt);
307315

308-
if our_hash != password_hash {
316+
if our_hash != password_hash {
309317
wrong_password(write, &self.username).await?;
310318

311319
Err(Error::ClientError(format!(
@@ -324,15 +332,24 @@ impl Md5 {
324332

325333
let hash = match hash {
326334
Some(hash) => hash.to_string(),
327-
None => refetch_auth_hash(&pool, write, &self.username, &self.pool_name).await?,
335+
None => {
336+
refetch_auth_hash(&pool, write, &self.username, &self.pool_name)
337+
.await?
338+
}
328339
};
329340

330341
let our_hash = md5_hash_second_pass(&hash, &self.salt);
331342

332343
// Compare hashes
333344
if our_hash != password_hash {
334345
// Server hash maybe changed
335-
let hash = refetch_auth_hash(&pool, write, &self.username, &self.pool_name).await?;
346+
let hash = refetch_auth_hash(
347+
&pool,
348+
write,
349+
&self.username,
350+
&self.pool_name,
351+
)
352+
.await?;
336353
let our_hash = md5_hash_second_pass(&hash, &self.salt);
337354

338355
if our_hash != password_hash {
@@ -345,7 +362,13 @@ impl Md5 {
345362
} else {
346363
(*pool.auth_hash.write()) = Some(hash);
347364

348-
validate_pool(write, pool.clone(), &self.username, &self.pool_name).await?;
365+
validate_pool(
366+
write,
367+
pool.clone(),
368+
&self.username,
369+
&self.pool_name,
370+
)
371+
.await?;
349372

350373
Ok(())
351374
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use std::sync::Arc;
6161
use tokio::sync::broadcast;
6262

6363
mod admin;
64-
mod auth_passthrough;
6564
mod auth;
65+
mod auth_passthrough;
6666
mod client;
6767
mod config;
6868
mod constants;

src/pool.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,10 @@ impl ConnectionPool {
218218
.collect::<Vec<Option<String>>>(),
219219
None => vec![],
220220
};
221-
221+
222222
secrets.push(None);
223223

224224
for secret in secrets {
225-
226225
let old_pool_ref = get_pool(pool_name, &user.username, secret.clone());
227226
let identifier = PoolIdentifier::new(pool_name, &user.username, secret.clone());
228227

@@ -362,7 +361,9 @@ impl ConnectionPool {
362361

363362
let pool = Pool::builder()
364363
.max_size(user.pool_size)
365-
.connection_timeout(std::time::Duration::from_millis(connect_timeout))
364+
.connection_timeout(std::time::Duration::from_millis(
365+
connect_timeout,
366+
))
366367
.idle_timeout(Some(std::time::Duration::from_millis(idle_timeout)))
367368
.test_on_check_out(false)
368369
.build(manager)

0 commit comments

Comments
 (0)