Skip to content

Commit 692353c

Browse files
authored
A couple things (#397)
* Format cleanup * fmt * finally
1 parent a62f6b0 commit 692353c

File tree

13 files changed

+366
-100
lines changed

13 files changed

+366
-100
lines changed

.circleci/pgcat.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ log_client_connections = false
3939
log_client_disconnections = false
4040

4141
# Reload config automatically if it changes.
42-
autoreload = true
42+
autoreload = 15000
4343

4444
# TLS
4545
tls_certificate = ".circleci/server.cert"

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
7+
[*.rs]
8+
indent_style = space
9+
indent_size = 4
10+
max_line_length = 120
11+
12+
[*.toml]
13+
indent_style = space
14+
indent_size = 2

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgcat"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

examples/docker/pgcat.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ log_client_connections = false
3838
# If we should log client disconnections
3939
log_client_disconnections = false
4040

41-
# Reload config automatically if it changes.
42-
autoreload = false
43-
4441
# TLS
4542
# tls_certificate = "server.cert"
4643
# tls_private_key = "server.key"

pgcat.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ log_client_connections = false
4545
log_client_disconnections = false
4646

4747
# When set to true, PgCat reloads configs if it detects a change in the config file.
48-
autoreload = false
48+
autoreload = 15000
4949

5050
# Number of worker threads the Runtime will use (4 by default).
5151
worker_threads = 5

src/auth_passthrough.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::errors::Error;
2+
use crate::pool::ConnectionPool;
23
use crate::server::Server;
34
use log::debug;
45

@@ -78,19 +79,25 @@ impl AuthPassthrough {
7879

7980
let user = &address.username;
8081

81-
debug!("Connecting to server to obtain auth hashes.");
82+
debug!("Connecting to server to obtain auth hashes");
83+
8284
let auth_query = self.query.replace("$1", user);
85+
8386
match Server::exec_simple_query(address, &auth_user, &auth_query).await {
8487
Ok(password_data) => {
8588
if password_data.len() == 2 && password_data.first().unwrap() == user {
86-
if let Some(stripped_hash) = password_data.last().unwrap().to_string().strip_prefix("md5") {
87-
Ok(stripped_hash.to_string())
88-
}
89-
else {
90-
Err(Error::AuthPassthroughError(
91-
"Obtained hash from auth_query does not seem to be in md5 format.".to_string(),
92-
))
93-
}
89+
if let Some(stripped_hash) = password_data
90+
.last()
91+
.unwrap()
92+
.to_string()
93+
.strip_prefix("md5") {
94+
Ok(stripped_hash.to_string())
95+
}
96+
else {
97+
Err(Error::AuthPassthroughError(
98+
"Obtained hash from auth_query does not seem to be in md5 format.".to_string(),
99+
))
100+
}
94101
} else {
95102
Err(Error::AuthPassthroughError(
96103
"Data obtained from query does not follow the scheme 'user','hash'."
@@ -99,10 +106,25 @@ impl AuthPassthrough {
99106
}
100107
}
101108
Err(err) => {
102-
Err(Error::AuthPassthroughError(
103-
format!("Error trying to obtain password from auth_query, ignoring hash for user '{}'. Error: {:?}",
104-
user, err)))
109+
Err(Error::AuthPassthroughError(
110+
format!("Error trying to obtain password from auth_query, ignoring hash for user '{}'. Error: {:?}",
111+
user, err))
112+
)
105113
}
106-
}
114+
}
115+
}
116+
}
117+
118+
pub async fn refetch_auth_hash(pool: &ConnectionPool) -> Result<String, Error> {
119+
let address = pool.address(0, 0);
120+
if let Some(apt) = AuthPassthrough::from_pool_settings(&pool.settings) {
121+
let hash = apt.fetch_hash(address).await?;
122+
123+
return Ok(hash);
107124
}
125+
126+
Err(Error::ClientError(format!(
127+
"Could not obtain hash for {{ username: {:?}, database: {:?} }}. Auth passthrough not enabled.",
128+
address.username, address.database
129+
)))
108130
}

0 commit comments

Comments
 (0)