@@ -67,23 +67,38 @@ class NativeConfiguration {
67
67
return ! ! process . env . MONGODB_UNIFIED_TOPOLOGY ;
68
68
}
69
69
70
+ get tlsOptions ( ) {
71
+ const tlsCertificateKeyFile = process . env . SSL_KEY_FILE ;
72
+ const tlsCAFile = process . env . SSL_CA_FILE ;
73
+ if ( tlsCertificateKeyFile && tlsCertificateKeyFile ) {
74
+ return { tls : true , tlsCertificateKeyFile, tlsCAFile } ;
75
+ }
76
+ return { } ;
77
+ }
78
+
79
+ get unifiedOptions ( ) {
80
+ if ( this . usingUnifiedTopology ( ) ) {
81
+ return { useUnifiedTopology : true , minHeartbeatFrequencyMS : 100 } ;
82
+ }
83
+ return { } ;
84
+ }
85
+
70
86
newClient ( dbOptions , serverOptions ) {
71
87
// support MongoClient contructor form (url, options) for `newClient`
72
88
if ( typeof dbOptions === 'string' ) {
73
89
return new MongoClient (
74
90
dbOptions ,
75
- this . usingUnifiedTopology ( )
76
- ? Object . assign ( { useUnifiedTopology : true , minHeartbeatFrequencyMS : 100 } , serverOptions )
77
- : serverOptions
91
+ Object . assign ( { } , this . unifiedOptions , this . tlsOptions , serverOptions )
78
92
) ;
79
93
}
80
94
81
95
dbOptions = dbOptions || { } ;
82
- serverOptions = Object . assign ( { } , { haInterval : 100 } , serverOptions ) ;
83
- if ( this . usingUnifiedTopology ( ) ) {
84
- serverOptions . useUnifiedTopology = true ;
85
- serverOptions . minHeartbeatFrequencyMS = 100 ;
86
- }
96
+ serverOptions = Object . assign (
97
+ { haInterval : 100 } ,
98
+ this . unifiedOptions ,
99
+ this . tlsOptions ,
100
+ serverOptions
101
+ ) ;
87
102
88
103
// Fall back
89
104
let dbHost = ( serverOptions && serverOptions . host ) || this . options . host ;
0 commit comments