@@ -49,16 +49,20 @@ fn maybe_append_url_param(url: &mut Url, key: &str, value: &str) {
49
49
50
50
/// Create a new [ManagerConfig] for the database connection pool, which can
51
51
/// be used with [diesel_async::pooled_connection::AsyncDieselConnectionManager::new_with_config()].
52
- pub fn make_manager_config ( ) -> ManagerConfig < AsyncPgConnection > {
52
+ pub fn make_manager_config ( enforce_tls : bool ) -> ManagerConfig < AsyncPgConnection > {
53
53
let mut manager_config = ManagerConfig :: default ( ) ;
54
- manager_config. custom_setup = Box :: new ( |url| Box :: pin ( establish_async_connection ( url) ) ) ;
54
+ manager_config. custom_setup =
55
+ Box :: new ( |url| Box :: pin ( establish_async_connection ( url, enforce_tls) ) ) ;
55
56
manager_config
56
57
}
57
58
58
59
/// Establish a new database connection with the given URL.
59
60
///
60
61
/// Adapted from <https://github.com/weiznich/diesel_async/blob/v0.5.0/examples/postgres/pooled-with-rustls/src/main.rs>.
61
- async fn establish_async_connection ( url : & str ) -> ConnectionResult < AsyncPgConnection > {
62
+ async fn establish_async_connection (
63
+ url : & str ,
64
+ enforce_tls : bool ,
65
+ ) -> ConnectionResult < AsyncPgConnection > {
62
66
use diesel:: ConnectionError :: BadConnection ;
63
67
64
68
let cert = Certificate :: from_pem ( CRUNCHY ) . map_err ( |err| BadConnection ( err. to_string ( ) ) ) ?;
@@ -72,7 +76,7 @@ async fn establish_async_connection(url: &str) -> ConnectionResult<AsyncPgConnec
72
76
//
73
77
// See also https://github.com/sfackler/rust-native-tls/issues/143.
74
78
//
75
- // .danger_accept_invalid_certs(true )
79
+ . danger_accept_invalid_certs ( !enforce_tls )
76
80
. build ( )
77
81
. map_err ( |err| BadConnection ( err. to_string ( ) ) ) ?;
78
82
0 commit comments