Created
August 18, 2016 09:52
-
-
Save dziamid/6ced2c5bd964acc0e127047cf9cedb45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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