src/Ssh/Ssh.js
/**
	 * Setup a tunnel for the given Db instance
	 * @param {Db} db  A Db instance
	 * @returns {Promise}  Resolves when tunnel is established
	 */
Setup a tunnel for the given Db instance
@param {Db} db  A Db instance
@returns {Promise}  Resolves when tunnel is established
Setup a tunnel for the given Db instance @param { Db } db A Db instance @returns { Promise } Resolves when tunnel is established
tunnelTo(db) {
		return new Promise((resolve, reject) => {
			if (!db.config || !db.config.host || !db.config.port) {
				reject(new Error('Db config must have host and port.'));
			}
			this.connection = new Client();
			this.connection.on('ready', () => {
				this.connection.forwardOut(
					'127.0.0.1',
					this.config.localPort,
					db.config.host,
					db.config.port,
					(err, stream) => {
						if (err) {
							this.end();
							return reject(err);
						}
						db.config.host = 'localhost';
						db.config.stream = stream;
						resolve();
					}
				);
			});
			this.connection.connect(this.config);
		});
	}
tunnelTo ( db ) { return new Promise ( ( resolve , reject ) => { if ( ! db . config || ! db . config . host || ! db . config . port ) { reject ( new Error ( 'Db config must have host and port.' ) ) ; } this . connection = new Client ( ) ; this . connection . on ( 'ready' , ( ) => { this . connection . forwardOut ( '127.0.0.1' , this . config . localPort , db . config . host , db . config . port , ( err , stream ) => { if ( err ) { this . end ( ) ; return reject ( err ) ; } db . config . host = 'localhost' ; db . config . stream = stream ; resolve ( ) ; } ) ; } ) ; this . connection . connect ( this . config ) ; } ) ; }
Setup a tunnel for the given Db instance
 @param {Db} db  A Db instance
 @returns {Promise}  Resolves when tunnel is established
Setup a tunnel for the given Db instance @param { Db } db A Db instance @returns { Promise } Resolves when tunnel is established
// override db host, since we're operating from within the SSH tunnel