@@ -25,29 +25,15 @@ var val = function (key, config, envVar) {
25
25
return config [ key ] || envVar || defaults [ key ]
26
26
}
27
27
28
- var normalizeSSLConfig = function ( modeFromConfig ) {
29
- // if the ssl parameter passed to config is not a string, just return it
30
- // directly (it will be passed directly to tls.connect)
31
- // this way you can pass all the ssl params in via constructor:
32
- // new Client({ ssl: { minDHSize: 1024 } }) etc
33
- if ( modeFromConfig !== undefined && typeof modeFromConfig !== 'string' ) {
34
- return modeFromConfig
35
- }
36
- const mode = modeFromConfig || process . env . PGSSLMODE
37
-
38
- switch ( mode ) {
28
+ var readSSLConfigFromEnvironment = function ( ) {
29
+ switch ( process . env . PGSSLMODE ) {
39
30
case 'disable' :
40
31
return false
41
32
case 'prefer' :
42
33
case 'require' :
43
34
case 'verify-ca' :
44
35
case 'verify-full' :
45
36
return true
46
- // no-verify is not standard to libpq but allows specifying
47
- // you require ssl but want to bypass server certificate validation.
48
- // this is a very common way to connect in heroku so we support it
49
- // vai both environment variables (PGSSLMODE=no-verify) as well
50
- // as in connection string params ?ssl=no-verify
51
37
case 'no-verify' :
52
38
return { rejectUnauthorized : false }
53
39
}
@@ -85,7 +71,13 @@ var ConnectionParameters = function (config) {
85
71
86
72
this . binary = val ( 'binary' , config )
87
73
88
- this . ssl = normalizeSSLConfig ( config . ssl )
74
+ this . ssl = typeof config . ssl === 'undefined' ? readSSLConfigFromEnvironment ( ) : config . ssl
75
+
76
+ // support passing in ssl=no-verify via connection string
77
+ if ( this . ssl === 'no-verify' ) {
78
+ this . ssl = { rejectUnauthorized : false }
79
+ }
80
+
89
81
this . client_encoding = val ( 'client_encoding' , config )
90
82
this . replication = val ( 'replication' , config )
91
83
// a domain socket begins with '/'
0 commit comments