Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make clippy lint happy #225

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn generate_server_info_for_admin() -> BytesMut {
server_info.put(server_parameter_message("server_version", VERSION));
server_info.put(server_parameter_message("DateStyle", "ISO, MDY"));

return server_info;
server_info
}

/// Handle admin client.
Expand Down Expand Up @@ -179,7 +179,7 @@ where
let mut res = BytesMut::new();

res.put(row_description(&vec![("version", DataType::Text)]));
res.put(data_row(&vec![format!("PgCat {}", VERSION).to_string()]));
res.put(data_row(&vec![format!("PgCat {}", VERSION)]));
res.put(command_complete("SHOW"));

res.put_u8(b'Z');
Expand Down
41 changes: 19 additions & 22 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ where

let admin = ["pgcat", "pgbouncer"]
.iter()
.filter(|db| *db == &pool_name)
.filter(|db| *db == pool_name)
.count()
== 1;

Expand All @@ -389,7 +389,7 @@ where
);
error_response_terminal(
&mut write,
&format!("terminating connection due to administrator command"),
"terminating connection due to administrator command",
)
.await?;
return Err(Error::ShuttingDown);
Expand Down Expand Up @@ -446,7 +446,7 @@ where
}
// Authenticate normal user.
else {
let pool = match get_pool(&pool_name, &username) {
let pool = match get_pool(pool_name, username) {
Some(pool) => pool,
None => {
error_response(
Expand All @@ -464,7 +464,7 @@ where
};

// Compare server and client hashes.
let password_hash = md5_hash_password(&username, &pool.settings.user.password, &salt);
let password_hash = md5_hash_password(username, &pool.settings.user.password, &salt);

if password_hash != password_response {
warn!("Invalid password {{ username: {:?}, pool_name: {:?}, application_name: {:?} }}", pool_name, username, application_name);
Expand All @@ -487,9 +487,9 @@ where

trace!("Startup OK");

return Ok(Client {
Ok(Client {
read: BufReader::new(read),
write: write,
write,
addr,
buffer: BytesMut::with_capacity(8196),
cancel_mode: false,
Expand All @@ -498,16 +498,16 @@ where
secret_key,
client_server_map,
parameters: parameters.clone(),
stats: stats,
admin: admin,
stats,
admin,
last_address_id: None,
last_server_id: None,
pool_name: pool_name.clone(),
username: username.clone(),
application_name: application_name.to_string(),
shutdown,
connected_to_server: false,
});
})
}

/// Handle cancel request.
Expand All @@ -521,9 +521,9 @@ where
) -> Result<Client<S, T>, Error> {
let process_id = bytes.get_i32();
let secret_key = bytes.get_i32();
return Ok(Client {
Ok(Client {
read: BufReader::new(read),
write: write,
write,
addr,
buffer: BytesMut::with_capacity(8196),
cancel_mode: true,
Expand All @@ -541,7 +541,7 @@ where
application_name: String::from("undefined"),
shutdown,
connected_to_server: false,
});
})
}

/// Handle a connected and authenticated client.
Expand All @@ -557,12 +557,9 @@ where
// Drop the mutex as soon as possible.
// We found the server the client is using for its query
// that it wants to cancel.
Some((process_id, secret_key, address, port)) => (
process_id.clone(),
secret_key.clone(),
address.clone(),
*port,
),
Some((process_id, secret_key, address, port)) => {
(*process_id, *secret_key, address.clone(), *port)
}

// The client doesn't know / got the wrong server,
// we're closing the connection for security reasons.
Expand All @@ -573,7 +570,7 @@ where
// Opens a new separate connection to the server, sends the backend_id
// and secret_key and then closes it for security reasons. No other interactions
// take place.
return Ok(Server::cancel(&address, port, process_id, secret_key).await?);
return Server::cancel(&address, port, process_id, secret_key).await;
}

// The query router determines where the query is going to go,
Expand Down Expand Up @@ -606,7 +603,7 @@ where
if !self.admin {
error_response_terminal(
&mut self.write,
&format!("terminating connection due to administrator command")
"terminating connection due to administrator command"
).await?;
return Ok(())
}
Expand Down Expand Up @@ -998,14 +995,14 @@ where
) -> Result<(), Error> {
debug!("Sending {} to server", code);

self.send_server_message(server, message, &address, &pool)
self.send_server_message(server, message, address, pool)
.await?;

let query_start = Instant::now();
// Read all data the server has to offer, which can be multiple messages
// buffered in 8196 bytes chunks.
loop {
let response = self.receive_server_message(server, &address, &pool).await?;
let response = self.receive_server_message(server, address, pool).await?;

match write_all_half(&mut self.write, response).await {
Ok(_) => (),
Expand Down
31 changes: 12 additions & 19 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::path::Path;
use std::sync::Arc;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use toml;

use crate::errors::Error;
use crate::pool::{ClientServerMap, ConnectionPool};
Expand Down Expand Up @@ -353,7 +352,7 @@ impl Shard {
let mut dup_check = HashSet::new();
let mut primary_count = 0;

if self.servers.len() == 0 {
if self.servers.is_empty() {
error!("Shard {} has no servers configured", self.database);
return Err(Error::BadConfig);
}
Expand All @@ -362,10 +361,9 @@ impl Shard {
dup_check.insert(server);

// Check that we define only zero or one primary.
match server.role {
Role::Primary => primary_count += 1,
_ => (),
};
if server.role == Role::Primary {
primary_count += 1
}
}

if primary_count > 1 {
Expand Down Expand Up @@ -605,22 +603,17 @@ impl Config {
// Validate TLS!
match self.general.tls_certificate.clone() {
Some(tls_certificate) => {
match load_certs(&Path::new(&tls_certificate)) {
match load_certs(Path::new(&tls_certificate)) {
Ok(_) => {
// Cert is okay, but what about the private key?
match self.general.tls_private_key.clone() {
Some(tls_private_key) => {
match load_keys(&Path::new(&tls_private_key)) {
Ok(_) => (),
Err(err) => {
error!(
"tls_private_key is incorrectly configured: {:?}",
err
);
return Err(Error::BadConfig);
}
Some(tls_private_key) => match load_keys(Path::new(&tls_private_key)) {
Ok(_) => (),
Err(err) => {
error!("tls_private_key is incorrectly configured: {:?}", err);
return Err(Error::BadConfig);
}
}
},

None => {
error!("tls_certificate is set, but the tls_private_key is not");
Expand All @@ -638,7 +631,7 @@ impl Config {
None => (),
};

for (_, pool) in &mut self.pools {
for pool in self.pools.values_mut() {
pool.validate()?;
}

Expand Down
23 changes: 4 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ mod stats;
mod tls;

use crate::config::{get_config, reload_config, VERSION};
use crate::errors::Error;
use crate::pool::{ClientServerMap, ConnectionPool};
use crate::prometheus::start_metric_server;
use crate::stats::{Collector, Reporter, REPORTER};
Expand Down Expand Up @@ -171,13 +170,10 @@ async fn main() {
if config.general.autoreload {
info!("Automatically reloading config");

match reload_config(autoreload_client_server_map.clone()).await {
Ok(changed) => {
if changed {
get_config().show()
}
if let Ok(changed) = reload_config(autoreload_client_server_map.clone()).await {
if changed {
get_config().show()
}
Err(_) => (),
};
}
}
Expand All @@ -202,10 +198,7 @@ async fn main() {
_ = sighup_signal.recv() => {
info!("Reloading config");

match reload_config(client_server_map.clone()).await {
Ok(_) => (),
Err(_) => (),
};
_ = reload_config(client_server_map.clone()).await;

get_config().show();
},
Expand Down Expand Up @@ -278,14 +271,6 @@ async fn main() {
}

Err(err) => {
match err {
// Don't count the clients we rejected.
Error::ShuttingDown => (),
_ => {
// drain_tx.send(-1).await.unwrap();
}
}

warn!("Client disconnected with error {:?}", err);
}
};
Expand Down
Loading