Skip to content

Commit 37feaf9

Browse files
committed
Fixed problem with require sslmode
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent 6f930d7 commit 37feaf9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/driver/connection_pool_builder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
use std::{net::IpAddr, time::Duration};
22

33
use deadpool_postgres::{Manager, ManagerConfig, Pool, RecyclingMethod};
4-
use openssl::ssl::{SslConnector, SslMethod};
4+
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
55
use postgres_openssl::MakeTlsConnector;
66
use pyo3::{pyclass, pymethods, Py, Python};
77
use tokio_postgres::NoTls;
88

99
use crate::exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult};
1010

11-
use super::connection_pool::ConnectionPool;
11+
use super::{common_options, connection_pool::ConnectionPool};
1212

1313
#[pyclass]
1414
pub struct ConnectionPoolBuilder {
1515
config: tokio_postgres::Config,
1616
max_db_pool_size: Option<usize>,
1717
conn_recycling_method: Option<RecyclingMethod>,
1818
ca_file: Option<String>,
19+
ssl_mode: Option<common_options::SslMode>,
1920
}
2021

2122
#[pymethods]
@@ -28,6 +29,7 @@ impl ConnectionPoolBuilder {
2829
max_db_pool_size: Some(2),
2930
conn_recycling_method: None,
3031
ca_file: None,
32+
ssl_mode: None,
3133
}
3234
}
3335

@@ -53,6 +55,15 @@ impl ConnectionPoolBuilder {
5355
builder.set_ca_file(ca_file)?;
5456
let tls_connector = MakeTlsConnector::new(builder.build());
5557
mgr = Manager::from_config(self.config.clone(), tls_connector, mgr_config);
58+
} else if let Some(ssl_mode) = self.ssl_mode {
59+
if ssl_mode == common_options::SslMode::Require {
60+
let mut builder = SslConnector::builder(SslMethod::tls())?;
61+
builder.set_verify(SslVerifyMode::NONE);
62+
let tls_connector = MakeTlsConnector::new(builder.build());
63+
mgr = Manager::from_config(self.config.clone(), tls_connector, mgr_config);
64+
} else {
65+
mgr = Manager::from_config(self.config.clone(), NoTls, mgr_config);
66+
}
5667
} else {
5768
mgr = Manager::from_config(self.config.clone(), NoTls, mgr_config);
5869
}
@@ -167,6 +178,7 @@ impl ConnectionPoolBuilder {
167178
pub fn ssl_mode(self_: Py<Self>, ssl_mode: crate::driver::common_options::SslMode) -> Py<Self> {
168179
Python::with_gil(|gil| {
169180
let mut self_ = self_.borrow_mut(gil);
181+
self_.ssl_mode = Some(ssl_mode);
170182
self_.config.ssl_mode(ssl_mode.to_internal());
171183
});
172184
self_

0 commit comments

Comments
 (0)