Skip to content

Commit cb87a3e

Browse files
authored
Merge pull request #447 from ali-ince/2.0-api-changes
Remove deprecated API
2 parents e1b28f3 + 97e842a commit cb87a3e

19 files changed

+53
-665
lines changed

src/driver.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class Driver {
9393
*/
9494
this._connectionProvider = null;
9595

96-
this._onCompleted = null;
97-
9896
this._afterConstruction();
9997
}
10098

@@ -106,26 +104,13 @@ class Driver {
106104
}
107105

108106
/**
109-
* Get the installed connectivity verification callback.
110-
* @return {null|function}
111-
* @deprecated driver can be used directly once instantiated, use of this callback is not required.
107+
* Verifies connectivity of this driver by trying to open a connection with the provided driver options.
108+
* @returns {Promise<object>} promise resolved with server info or rejected with error.
112109
*/
113-
get onCompleted() {
114-
return this._onCompleted;
115-
}
116-
117-
/**
118-
* Install a connectivity verification callback.
119-
* @param {null|function} callback the new function to be notified about successful connection.
120-
* @deprecated driver can be used directly once instantiated, use of this callback is not required.
121-
*/
122-
set onCompleted(callback) {
123-
this._onCompleted = callback;
124-
if (this._onCompleted) {
125-
const connectionProvider = this._getOrCreateConnectionProvider();
126-
const connectivityVerifier = new ConnectivityVerifier(connectionProvider, this._onCompleted);
127-
connectivityVerifier.verify();
128-
}
110+
verifyConnectivity() {
111+
const connectionProvider = this._getOrCreateConnectionProvider();
112+
const connectivityVerifier = new ConnectivityVerifier(connectionProvider);
113+
return connectivityVerifier.verify();
129114
}
130115

131116
/**

src/index.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,42 +103,23 @@ const logging = {
103103
* // TRUST_ALL_CERTIFICATES is the default choice for NodeJS deployments. It only requires
104104
* // new host to provide a certificate and does no verification of the provided certificate.
105105
* //
106-
* // TRUST_ON_FIRST_USE is available for modern NodeJS deployments, and works
107-
* // similarly to how `ssl` works - the first time we connect to a new host,
108-
* // we remember the certificate they use. If the certificate ever changes, we
109-
* // assume it is an attempt to hijack the connection and require manual intervention.
110-
* // This means that by default, connections "just work" while still giving you
111-
* // good encrypted protection.
112-
* //
113106
* // TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is the classic approach to trust verification -
114107
* // whenever we establish an encrypted connection, we ensure the host is using
115108
* // an encryption certificate that is in, or is signed by, a certificate listed
116109
* // as trusted. In the web bundle, this list of trusted certificates is maintained
117110
* // by the web browser. In NodeJS, you configure the list with the next config option.
118111
* //
119112
* // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES means that you trust whatever certificates
120-
* // are in the default certificate chain of th
121-
* trust: "TRUST_ALL_CERTIFICATES" | "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES" |
122-
* "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" | "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
113+
* // are in the default certificate chain of the underlying system.
114+
* trust: "TRUST_ALL_CERTIFICATES" | "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" |
115+
* "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
123116
*
124117
* // List of one or more paths to trusted encryption certificates. This only
125118
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
126119
* // The certificate files should be in regular X.509 PEM format.
127120
* // For instance, ['./trusted.pem']
128121
* trustedCertificates: [],
129122
*
130-
* // Path to a file where the driver saves hosts it has seen in the past, this is
131-
* // very similar to the ssl tool's known_hosts file. Each time we connect to a
132-
* // new host, a hash of their certificate is stored along with the domain name and
133-
* // port, and this is then used to verify the host certificate does not change.
134-
* // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
135-
* knownHosts:"~/.neo4j/known_hosts",
136-
*
137-
* // The max number of connections that are allowed idle in the pool at any time.
138-
* // Connection will be destroyed if this threshold is exceeded.
139-
* // **Deprecated:** please use `maxConnectionPoolSize` instead.
140-
* connectionPoolSize: 100,
141-
*
142123
* // The maximum total number of connections allowed to be managed by the connection pool, per host.
143124
* // This includes both in-use and idle connections. No maximum connection pool size is imposed
144125
* // by default.
@@ -164,12 +145,6 @@ const logging = {
164145
* // Default value is 30000 which is 30 seconds.
165146
* maxTransactionRetryTime: 30000, // 30 seconds
166147
*
167-
* // Provide an alternative load balancing strategy for the routing driver to use.
168-
* // Driver uses "least_connected" by default.
169-
* // **Note:** We are experimenting with different strategies. This could be removed in the next minor
170-
* // version.
171-
* loadBalancingStrategy: "least_connected" | "round_robin",
172-
*
173148
* // Specify socket connection timeout in milliseconds. Numeric values are expected. Negative and zero values
174149
* // result in no timeout being applied. Connection establishment will be then bound by the timeout configured
175150
* // on the operating system level. Default value is 5000, which is 5 seconds.

src/internal/channel-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000; // 5 seconds by default
2424

2525
const ALLOWED_VALUES_ENCRYPTED = [null, undefined, true, false, ENCRYPTION_ON, ENCRYPTION_OFF];
2626

27-
const ALLOWED_VALUES_TRUST = [null, undefined, 'TRUST_ALL_CERTIFICATES', 'TRUST_ON_FIRST_USE',
28-
'TRUST_SIGNED_CERTIFICATES', 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES', 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES'];
27+
const ALLOWED_VALUES_TRUST = [null, undefined, 'TRUST_ALL_CERTIFICATES',
28+
'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES', 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES'];
2929

3030
export default class ChannelConfig {
3131

src/internal/connectivity-verifier.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@ export default class ConnectivityVerifier {
2929
/**
3030
* @constructor
3131
* @param {ConnectionProvider} connectionProvider the provider to obtain connections from.
32-
* @param {function} successCallback a callback to invoke when verification succeeds.
3332
*/
34-
constructor(connectionProvider, successCallback) {
33+
constructor(connectionProvider) {
3534
this._connectionProvider = connectionProvider;
36-
this._successCallback = successCallback;
3735
}
3836

37+
/**
38+
* Try to obtain a working connection from the connection provider.
39+
* @returns {Promise<object>} promise resolved with server info or rejected with error.
40+
*/
3941
verify() {
40-
acquireAndReleaseDummyConnection(this._connectionProvider).then(serverInfo => {
41-
if (this._successCallback) {
42-
this._successCallback(serverInfo);
43-
}
44-
}).catch(ignoredError => {
45-
});
42+
return acquireAndReleaseDummyConnection(this._connectionProvider);
4643
}
4744
}
4845

src/internal/node/node-channel.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ function storeFingerprint( serverId, knownHostsPath, fingerprint, cb ) {
106106
}
107107

108108
const TrustStrategy = {
109-
/**
110-
* @deprecated Since version 1.0. Will be deleted in a future version. {@link #TRUST_CUSTOM_CA_SIGNED_CERTIFICATES}.
111-
*/
112-
TRUST_SIGNED_CERTIFICATES: function( config, onSuccess, onFailure ) {
113-
console.warn('`TRUST_SIGNED_CERTIFICATES` has been deprecated as option and will be removed in a future version of ' +
114-
"the driver. Please use `TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead.");
115-
return TrustStrategy.TRUST_CUSTOM_CA_SIGNED_CERTIFICATES(config, onSuccess, onFailure);
116-
},
117109
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES : function( config, onSuccess, onFailure ) {
118110
if( !config.trustedCertificates || config.trustedCertificates.length === 0 ) {
119111
onFailure(newError("You are using TRUST_CUSTOM_CA_SIGNED_CERTIFICATES as the method " +
@@ -159,62 +151,6 @@ const TrustStrategy = {
159151
socket.on('error', onFailure);
160152
return configureSocket(socket);
161153
},
162-
/**
163-
* @deprecated in 1.1 in favour of {@link #TRUST_ALL_CERTIFICATES}. Will be deleted in a future version.
164-
*/
165-
TRUST_ON_FIRST_USE : function( config, onSuccess, onFailure ) {
166-
console.warn('`TRUST_ON_FIRST_USE` has been deprecated as option and will be removed in a future version of ' +
167-
"the driver. Please use `TRUST_ALL_CERTIFICATES` instead.");
168-
169-
const tlsOpts = newTlsOptions(config.url.host);
170-
const socket = tls.connect(config.url.port, config.url.host, tlsOpts, function () {
171-
const serverCert = socket.getPeerCertificate(/*raw=*/true);
172-
173-
if( !serverCert.raw ) {
174-
// If `raw` is not available, we're on an old version of NodeJS, and
175-
// the raw cert cannot be accessed (or, at least I couldn't find a way to)
176-
// therefore, we can't generate a SHA512 fingerprint, meaning we can't
177-
// do TOFU, and the safe approach is to fail.
178-
onFailure(newError("You are using a version of NodeJS that does not " +
179-
"support trust-on-first use encryption. You can either upgrade NodeJS to " +
180-
"a newer version, use `trust:TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` in your driver " +
181-
"config instead, or disable encryption using `encrypted:\"" + ENCRYPTION_OFF+ "\"`."));
182-
return;
183-
}
184-
185-
const serverFingerprint = crypto.createHash('sha512').update(serverCert.raw).digest('hex');
186-
const knownHostsPath = config.knownHostsPath || path.join(userHome(), ".neo4j", "known_hosts");
187-
const serverId = config.url.hostAndPort;
188-
189-
loadFingerprint(serverId, knownHostsPath, (knownFingerprint) => {
190-
if( knownFingerprint === serverFingerprint ) {
191-
onSuccess();
192-
} else if( knownFingerprint == null ) {
193-
storeFingerprint( serverId, knownHostsPath, serverFingerprint, (err) => {
194-
if (err) {
195-
return onFailure(err);
196-
}
197-
return onSuccess();
198-
});
199-
} else {
200-
onFailure(newError("Database encryption certificate has changed, and no longer " +
201-
"matches the certificate stored for " + serverId + " in `" + knownHostsPath +
202-
"`. As a security precaution, this driver will not automatically trust the new " +
203-
"certificate, because doing so would allow an attacker to pretend to be the Neo4j " +
204-
"instance we want to connect to. The certificate provided by the server looks like: " +
205-
serverCert + ". If you trust that this certificate is valid, simply remove the line " +
206-
"starting with " + serverId + " in `" + knownHostsPath + "`, and the driver will " +
207-
"update the file with the new certificate. You can configure which file the driver " +
208-
"should use to store this information by setting `knownHosts` to another path in " +
209-
"your driver configuration - and you can disable encryption there as well using " +
210-
"`encrypted:\"" + ENCRYPTION_OFF + "\"`."))
211-
}
212-
});
213-
});
214-
socket.on('error', onFailure);
215-
return configureSocket(socket);
216-
},
217-
218154
TRUST_ALL_CERTIFICATES: function (config, onSuccess, onFailure) {
219155
const tlsOpts = newTlsOptions(config.url.host);
220156
const socket = tls.connect(config.url.port, config.url.host, tlsOpts, function () {

src/internal/pool-config.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,8 @@ export default class PoolConfig {
3232
}
3333

3434
static fromDriverConfig(config) {
35-
const maxIdleSizeConfigured = isConfigured(config.connectionPoolSize);
3635
const maxSizeConfigured = isConfigured(config.maxConnectionPoolSize);
37-
38-
let maxSize;
39-
40-
if (maxSizeConfigured) {
41-
// correct size setting is set - use it's value
42-
maxSize = config.maxConnectionPoolSize;
43-
} else if (maxIdleSizeConfigured) {
44-
// deprecated size setting is set - use it's value
45-
console.warn('WARNING: neo4j-driver setting "connectionPoolSize" is deprecated, please use "maxConnectionPoolSize" instead');
46-
maxSize = config.connectionPoolSize;
47-
} else {
48-
maxSize = DEFAULT_MAX_SIZE;
49-
}
50-
36+
const maxSize = maxSizeConfigured ? config.maxConnectionPoolSize : DEFAULT_MAX_SIZE;
5137
const acquisitionTimeoutConfigured = isConfigured(config.connectionAcquisitionTimeout);
5238
const acquisitionTimeout = acquisitionTimeoutConfigured ? config.connectionAcquisitionTimeout : DEFAULT_ACQUISITION_TIMEOUT;
5339

src/internal/round-robin-load-balancing-strategy.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/routing-driver.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {Driver} from './driver';
2121
import {newError, SESSION_EXPIRED} from './error';
2222
import {LoadBalancer} from './internal/connection-providers';
2323
import LeastConnectedLoadBalancingStrategy, {LEAST_CONNECTED_STRATEGY_NAME} from './internal/least-connected-load-balancing-strategy';
24-
import RoundRobinLoadBalancingStrategy, {ROUND_ROBIN_STRATEGY_NAME} from './internal/round-robin-load-balancing-strategy';
2524
import ConnectionErrorHandler from './internal/connection-error-handler';
2625
import ConfiguredHostNameResolver from './internal/resolver/configured-host-name-resolver';
2726
import {HostNameResolver} from './internal/node';
@@ -75,14 +74,7 @@ class RoutingDriver extends Driver {
7574
* @private
7675
*/
7776
static _createLoadBalancingStrategy(config, connectionPool) {
78-
const configuredValue = config.loadBalancingStrategy;
79-
if (!configuredValue || configuredValue === LEAST_CONNECTED_STRATEGY_NAME) {
80-
return new LeastConnectedLoadBalancingStrategy(connectionPool);
81-
} else if (configuredValue === ROUND_ROBIN_STRATEGY_NAME) {
82-
return new RoundRobinLoadBalancingStrategy();
83-
} else {
84-
throw newError('Unknown load balancing strategy: ' + configuredValue);
85-
}
77+
return new LeastConnectedLoadBalancingStrategy(connectionPool);
8678
}
8779
}
8880

@@ -102,9 +94,6 @@ function createHostNameResolver(config) {
10294
* @returns {object} the given config.
10395
*/
10496
function validateConfig(config) {
105-
if (config.trust === 'TRUST_ON_FIRST_USE') {
106-
throw newError('The chosen trust mode is not compatible with a routing driver');
107-
}
10897
const resolver = config.resolver;
10998
if (resolver && typeof resolver !== 'function') {
11099
throw new TypeError(`Configured resolver should be a function. Got: ${resolver}`);

0 commit comments

Comments
 (0)