|
20 | 20 | import hasFeature from './features';
|
21 | 21 | import {SERVICE_UNAVAILABLE} from '../error';
|
22 | 22 |
|
| 23 | +const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 0; // turned off by default |
| 24 | + |
23 | 25 | export default class ChannelConfig {
|
24 | 26 |
|
25 | 27 | constructor(host, port, driverConfig, connectionErrorCode) {
|
26 | 28 | this.host = host;
|
27 | 29 | this.port = port;
|
28 |
| - this.encrypted = ChannelConfig._extractEncrypted(driverConfig); |
29 |
| - this.trust = ChannelConfig._extractTrust(driverConfig); |
30 |
| - this.trustedCertificates = ChannelConfig._extractTrustedCertificates(driverConfig); |
31 |
| - this.knownHostsPath = ChannelConfig._extractKnownHostsPath(driverConfig); |
| 30 | + this.encrypted = extractEncrypted(driverConfig); |
| 31 | + this.trust = extractTrust(driverConfig); |
| 32 | + this.trustedCertificates = extractTrustedCertificates(driverConfig); |
| 33 | + this.knownHostsPath = extractKnownHostsPath(driverConfig); |
32 | 34 | this.connectionErrorCode = connectionErrorCode || SERVICE_UNAVAILABLE;
|
| 35 | + this.connectionTimeout = extractConnectionTimeout(driverConfig); |
33 | 36 | }
|
| 37 | +} |
34 | 38 |
|
35 |
| - static _extractEncrypted(driverConfig) { |
36 |
| - // check if encryption was configured by the user, use explicit null check because we permit boolean value |
37 |
| - const encryptionConfigured = driverConfig.encrypted == null; |
38 |
| - // default to using encryption if trust-all-certificates is available |
39 |
| - return encryptionConfigured ? hasFeature('trust_all_certificates') : driverConfig.encrypted; |
40 |
| - } |
| 39 | +function extractEncrypted(driverConfig) { |
| 40 | + // check if encryption was configured by the user, use explicit null check because we permit boolean value |
| 41 | + const encryptionConfigured = driverConfig.encrypted == null; |
| 42 | + // default to using encryption if trust-all-certificates is available |
| 43 | + return encryptionConfigured ? hasFeature('trust_all_certificates') : driverConfig.encrypted; |
| 44 | +} |
41 | 45 |
|
42 |
| - static _extractTrust(driverConfig) { |
43 |
| - if (driverConfig.trust) { |
44 |
| - return driverConfig.trust; |
45 |
| - } |
46 |
| - // default to using TRUST_ALL_CERTIFICATES if it is available |
47 |
| - return hasFeature('trust_all_certificates') ? 'TRUST_ALL_CERTIFICATES' : 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'; |
| 46 | +function extractTrust(driverConfig) { |
| 47 | + if (driverConfig.trust) { |
| 48 | + return driverConfig.trust; |
48 | 49 | }
|
| 50 | + // default to using TRUST_ALL_CERTIFICATES if it is available |
| 51 | + return hasFeature('trust_all_certificates') ? 'TRUST_ALL_CERTIFICATES' : 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'; |
| 52 | +} |
49 | 53 |
|
50 |
| - static _extractTrustedCertificates(driverConfig) { |
51 |
| - return driverConfig.trustedCertificates || []; |
52 |
| - } |
| 54 | +function extractTrustedCertificates(driverConfig) { |
| 55 | + return driverConfig.trustedCertificates || []; |
| 56 | +} |
| 57 | + |
| 58 | +function extractKnownHostsPath(driverConfig) { |
| 59 | + return driverConfig.knownHosts || null; |
| 60 | +} |
53 | 61 |
|
54 |
| - static _extractKnownHostsPath(driverConfig) { |
55 |
| - return driverConfig.knownHosts || null; |
| 62 | +function extractConnectionTimeout(driverConfig) { |
| 63 | + const configuredTimeout = parseInt(driverConfig.connectionTimeout, 10); |
| 64 | + if (!configuredTimeout || configuredTimeout < 0) { |
| 65 | + return DEFAULT_CONNECTION_TIMEOUT_MILLIS; |
56 | 66 | }
|
57 |
| -}; |
| 67 | + return configuredTimeout; |
| 68 | +} |
0 commit comments