Skip to content

Instantly share code, notes, and snippets.

@dziamid
Created August 18, 2016 09:52
Show Gist options
  • Save dziamid/6ced2c5bd964acc0e127047cf9cedb45 to your computer and use it in GitHub Desktop.
Save dziamid/6ced2c5bd964acc0e127047cf9cedb45 to your computer and use it in GitHub Desktop.
var ssh = require('ssh2');
var Promise = require('bluebird');
var sshConnection = new ssh.Client();
var sshConnectionReady = false;
sshConnection.connect({
host: config['QN_Address'],
port: 22,
username: 'ec2-user',
privateKey: require('fs').readFileSync(config['QN_Key'])
});
function getConnection() {
return new Promise((resolve, reject) => {
if (sshConnectionReady) {
resolve(sshConnection);
} else {
sshConnection
.once('ready', function () {
sshConnectionReady = true;
resolve(sshConnection);
})
.once('end', function () {
reject();
})
.once('error', function (error) {
reject(error);
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment