1
1
use std:: { net:: IpAddr , time:: Duration } ;
2
2
3
3
use deadpool_postgres:: { Manager , ManagerConfig , Pool , RecyclingMethod } ;
4
- use openssl:: ssl:: { SslConnector , SslMethod } ;
4
+ use openssl:: ssl:: { SslConnector , SslMethod , SslVerifyMode } ;
5
5
use postgres_openssl:: MakeTlsConnector ;
6
6
use pyo3:: { pyclass, pymethods, Py , Python } ;
7
7
use tokio_postgres:: NoTls ;
8
8
9
9
use crate :: exceptions:: rust_errors:: { RustPSQLDriverError , RustPSQLDriverPyResult } ;
10
10
11
- use super :: connection_pool:: ConnectionPool ;
11
+ use super :: { common_options , connection_pool:: ConnectionPool } ;
12
12
13
13
#[ pyclass]
14
14
pub struct ConnectionPoolBuilder {
15
15
config : tokio_postgres:: Config ,
16
16
max_db_pool_size : Option < usize > ,
17
17
conn_recycling_method : Option < RecyclingMethod > ,
18
18
ca_file : Option < String > ,
19
+ ssl_mode : Option < common_options:: SslMode > ,
19
20
}
20
21
21
22
#[ pymethods]
@@ -28,6 +29,7 @@ impl ConnectionPoolBuilder {
28
29
max_db_pool_size : Some ( 2 ) ,
29
30
conn_recycling_method : None ,
30
31
ca_file : None ,
32
+ ssl_mode : None ,
31
33
}
32
34
}
33
35
@@ -53,6 +55,15 @@ impl ConnectionPoolBuilder {
53
55
builder. set_ca_file ( ca_file) ?;
54
56
let tls_connector = MakeTlsConnector :: new ( builder. build ( ) ) ;
55
57
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
+ }
56
67
} else {
57
68
mgr = Manager :: from_config ( self . config . clone ( ) , NoTls , mgr_config) ;
58
69
}
@@ -167,6 +178,7 @@ impl ConnectionPoolBuilder {
167
178
pub fn ssl_mode ( self_ : Py < Self > , ssl_mode : crate :: driver:: common_options:: SslMode ) -> Py < Self > {
168
179
Python :: with_gil ( |gil| {
169
180
let mut self_ = self_. borrow_mut ( gil) ;
181
+ self_. ssl_mode = Some ( ssl_mode) ;
170
182
self_. config . ssl_mode ( ssl_mode. to_internal ( ) ) ;
171
183
} ) ;
172
184
self_
0 commit comments