Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

COMPASS-4017: Update driver and cleanup #210

Merged
merged 10 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 0 additions & 174 deletions .jsfmtrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- 10.2.1
- 12.4.0
addons:
apt:
sources:
Expand Down
37 changes: 0 additions & 37 deletions lib/connect-with-backoff.js

This file was deleted.

66 changes: 36 additions & 30 deletions lib/connect.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const { EventEmitter } = require('events');
const fs = require('fs');
const async = require('async');
const includes = require('lodash.includes');
const clone = require('lodash.clone');
const assign = require('lodash.assign');
const isString = require('lodash.isstring');
const isFunction = require('lodash.isfunction');
const omit = require('lodash.omit');
const MongoClient = require('mongodb').MongoClient;
const parseConnectionString = require('mongodb-core').parseConnectionString;
const {
includes,
clone,
assign,
isString,
isFunction,
omit
} = require('lodash');
const { MongoClient } = require('mongodb');
const { parseConnectionString } = require('mongodb/lib/core');
const Connection = require('./extended-model');
const createSSHTunnel = require('./ssh-tunnel');
const EventEmitter = require('events').EventEmitter;

const debug = require('debug')('mongodb-connection-model:connect');

const needToLoadSSLFiles = (model) => !includes(
['NONE', 'UNVALIDATED'],
model.sslType
);
const needToLoadSSLFiles = model =>
!includes(['NONE', 'UNVALIDATED'], model.sslType);

const loadOptions = (model, done) => {
if (!needToLoadSSLFiles(model)) {
Expand All @@ -28,18 +29,19 @@ const loadOptions = (model, done) => {
const tasks = {};
const opts = clone(model.driverOptions, true);

Object.keys(opts).map((key) => {
Object.keys(opts).map(key => {
if (key.indexOf('ssl') === -1) {
return;
}

if (Array.isArray(opts[key])) {
opts[key].forEach((value) => {
opts[key].forEach(value => {
if (typeof value === 'string') {
tasks[key] = (cb) => async.parallel(
opts[key].map((k) => fs.readFile.bind(null, k)),
cb
);
tasks[key] = cb =>
async.parallel(
opts[key].map(k => fs.readFile.bind(null, k)),
cb
);
}
});
}
Expand All @@ -60,7 +62,7 @@ const loadOptions = (model, done) => {
return done(err);
}

Object.keys(res).map((key) => {
Object.keys(res).map(key => {
opts[key] = res[key];
});

Expand Down Expand Up @@ -90,7 +92,7 @@ const validateURL = (model, done) => {
});
};

const getStatusStateString = (evt) => {
const getStatusStateString = evt => {
if (!evt) {
return 'UNKNOWN';
}
Expand Down Expand Up @@ -145,7 +147,7 @@ const getTasks = (model, setupListeners) => {
}
};

ctx.skip = (reason) => {
ctx.skip = reason => {
state.emit('status', { message, skipped: true, reason });

if (cb) {
Expand All @@ -167,19 +169,21 @@ const getTasks = (model, setupListeners) => {
* TODO (imlucas) dns.lookup() model.hostname and model.sshTunnelHostname to check for typos
*/
assign(tasks, {
'Load SSL files': (cb) => {
'Load SSL files': cb => {
const ctx = status('Load SSL files', cb);

if (!needToLoadSSLFiles(model)) {
return ctx.skip('The selected SSL mode does not need to load any files.');
return ctx.skip(
'The selected SSL mode does not need to load any files.'
);
}

loadOptions(model, ctx);
}
});

assign(tasks, {
'Create SSH Tunnel': (cb) => {
'Create SSH Tunnel': cb => {
const ctx = status('Create SSH Tunnel', cb);

if (model.sshTunnel === 'NONE') {
Expand All @@ -191,7 +195,7 @@ const getTasks = (model, setupListeners) => {
});

assign(tasks, {
'Connect to MongoDB': (cb) => {
'Connect to MongoDB': cb => {
const ctx = status('Connect to MongoDB');

// @note: Durran:
Expand Down Expand Up @@ -281,23 +285,25 @@ const connect = (model, setupListeners, done) => {
}

if (!isFunction(done)) {
done = (err) => {
done = err => {
if (err) {
throw err;
}
};
}

const tasks = getTasks(model, setupListeners);
const logTaskStatus = require('debug')('mongodb-connection-model:connect:status');
const logTaskStatus = require('debug')(
'mongodb-connection-model:connect:status'
);

tasks.state.on('status', (evt) => {
tasks.state.on('status', evt => {
logTaskStatus('%s [%s]', evt.message, getStatusStateString(evt));
});

logTaskStatus('Connecting...');

async.series(tasks, (err) => {
async.series(tasks, err => {
if (err) {
logTaskStatus('Error connecting:', err);

Expand Down
Loading