From 186f8be5b38a82364c804d6d5eb12c585e91a1d2 Mon Sep 17 00:00:00 2001 From: Lev Date: Mon, 27 Jun 2022 17:01:40 -0700 Subject: [PATCH] lint --- src/client.rs | 7 ++----- src/config.rs | 24 +++++++++++------------- src/main.rs | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/client.rs b/src/client.rs index 358982f..05895b6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,6 @@ /// Handle clients by pretending to be a PostgreSQL server. use bytes::{Buf, BufMut, BytesMut}; -use log::{debug, error, trace, info}; +use log::{debug, error, info, trace}; use std::collections::HashMap; use tokio::io::{split, AsyncReadExt, BufReader, ReadHalf, WriteHalf}; use tokio::net::TcpStream; @@ -82,7 +82,6 @@ pub async fn client_entrypoint( let addr = stream.peer_addr().unwrap(); match get_startup::(&mut stream).await { - // Client requested a TLS connection. Ok((ClientConnectionType::Tls, _)) => { let config = get_config(); @@ -105,7 +104,6 @@ pub async fn client_entrypoint( Err(err) => Err(err), } } - // TLS is not configured, we cannot offer it. else { // Rejecting client request for TLS. @@ -225,14 +223,13 @@ pub async fn startup_tls( // TLS negotitation failed. Err(err) => { error!("TLS negotiation failed: {:?}", err); - return Err(Error::TlsError) + return Err(Error::TlsError); } }; // TLS negotitation successful. // Continue with regular startup using encrypted connection. match get_startup::>(&mut stream).await { - // Got good startup message, proceeding like normal except we // are encrypted now. Ok((ClientConnectionType::Startup, bytes)) => { diff --git a/src/config.rs b/src/config.rs index 0e4b8d2..da59d2a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,15 +4,15 @@ use log::{error, info}; use once_cell::sync::Lazy; use serde_derive::Deserialize; use std::collections::{HashMap, HashSet}; +use std::path::Path; use std::sync::Arc; use tokio::fs::File; use tokio::io::AsyncReadExt; use toml; -use std::path::Path; use crate::errors::Error; -use crate::{ClientServerMap, ConnectionPool}; use crate::tls::{load_certs, load_keys}; +use crate::{ClientServerMap, ConnectionPool}; /// Globally available configuration. static CONFIG: Lazy> = Lazy::new(|| ArcSwap::from_pointee(Config::default())); @@ -264,7 +264,7 @@ impl Config { Some(tls_private_key) => { info!("TLS private key: {}", tls_private_key); info!("TLS support is enabled"); - }, + } None => (), } @@ -272,7 +272,7 @@ impl Config { None => { info!("TLS support is disabled"); - }, + } }; } } @@ -400,15 +400,13 @@ pub async fn parse(path: &str) -> Result<(), Error> { Ok(_) => { // Cert is okay, but what about the private key? match config.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"); @@ -422,7 +420,7 @@ pub async fn parse(path: &str) -> Result<(), Error> { return Err(Error::BadConfig); } } - }, + } None => (), }; diff --git a/src/main.rs b/src/main.rs index 7fb0ec6..49795b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,7 +163,7 @@ async fn main() { addr, format_duration(&duration) ); - }, + } Err(err) => { debug!("Client disconnected with error {:?}", err);