Skip to content

Commit

Permalink
fix(lint): use cloned method and fix rustfmt warning
Browse files Browse the repository at this point in the history
  • Loading branch information
youxq committed Sep 29, 2024
1 parent f3c2658 commit da82b63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
35 changes: 19 additions & 16 deletions quaint/src/connector/postgres/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use column_type::PGColumnType;
use futures::{future::FutureExt, lock::Mutex};
use lru_cache::LruCache;
use native_tls::{Certificate, Identity, TlsConnector};
use tokio::sync::OnceCell;
use postgres_native_tls::MakeTlsConnector;
use postgres_types::{Kind as PostgresKind, Type as PostgresType};
use std::hash::{DefaultHasher, Hash, Hasher};
Expand All @@ -37,6 +36,7 @@ use std::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use tokio::sync::OnceCell;
use tokio_postgres::{config::ChannelBinding, Client, Config, Statement};

/// The underlying postgres driver. Only available with the `expose-drivers`
Expand Down Expand Up @@ -905,28 +905,31 @@ impl MakeTlsConnectorManager {
}

pub async fn get_connector(&self) -> crate::Result<MakeTlsConnector> {
self.connector.get_or_try_init(|| async {
let mut tls_builder = TlsConnector::builder();
self.connector
.get_or_try_init(|| async {
let mut tls_builder = TlsConnector::builder();

{
let ssl_params = self.url.ssl_params();
let auth = ssl_params.to_owned().into_auth().await?;
{
let ssl_params = self.url.ssl_params();
let auth = ssl_params.to_owned().into_auth().await?;

if let Some(certificate) = auth.certificate.0 {
tls_builder.add_root_certificate(certificate);
}
if let Some(certificate) = auth.certificate.0 {
tls_builder.add_root_certificate(certificate);
}

tls_builder.danger_accept_invalid_certs(auth.ssl_accept_mode == SslAcceptMode::AcceptInvalidCerts);
tls_builder.danger_accept_invalid_certs(auth.ssl_accept_mode == SslAcceptMode::AcceptInvalidCerts);

if let Some(identity) = auth.identity.0 {
tls_builder.identity(identity);
if let Some(identity) = auth.identity.0 {
tls_builder.identity(identity);
}
}
}

let tls_connector = MakeTlsConnector::new(tls_builder.build()?);
let tls_connector = MakeTlsConnector::new(tls_builder.build()?);

Ok(tls_connector)
}).await.map(Clone::clone)
Ok(tls_connector)
})
.await
.cloned()
}
}

Expand Down
6 changes: 5 additions & 1 deletion quaint/src/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ impl Builder {
url.set_flavour(flavour);
}

if let QuaintManager::Postgres { ref mut url, tls_manager: _ } = self.manager {
if let QuaintManager::Postgres {
ref mut url,
tls_manager: _,
} = self.manager
{
url.set_flavour(flavour);
}
}
Expand Down
7 changes: 5 additions & 2 deletions quaint/src/pooled/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::connector::MssqlUrl;
#[cfg(feature = "mysql-native")]
use crate::connector::MysqlUrl;
#[cfg(feature = "postgresql-native")]
use crate::connector::{PostgresUrl, MakeTlsConnectorManager};
use crate::connector::{MakeTlsConnectorManager, PostgresUrl};
use crate::{
ast,
connector::{self, impl_default_TransactionCapable, IsolationLevel, Queryable, Transaction, TransactionCapable},
Expand Down Expand Up @@ -85,7 +85,10 @@ pub enum QuaintManager {
Mysql { url: MysqlUrl },

#[cfg(feature = "postgresql")]
Postgres { url: PostgresUrl, tls_manager: MakeTlsConnectorManager },
Postgres {
url: PostgresUrl,
tls_manager: MakeTlsConnectorManager,
},

#[cfg(feature = "sqlite")]
Sqlite { url: String, db_name: String },
Expand Down

0 comments on commit da82b63

Please sign in to comment.