Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
localPort,
username: serverDefinition.ssh.user,
port: serverDefinition.ssh.port,
host: serverDefinition.ssh.host,
dstPort: serverDefinition.port,
dstHost: serverDefinition.host,
};
if (serverDefinition.ssh.password) {
config.password = serverDefinition.ssh.password;
}
if (serverDefinition.ssh.privateKey) {
// TODO load content in async mode
config.privateKey = fs.readFileSync(serverDefinition.ssh.privateKey);
}
currentTunnel.server = tunnelssh(config);
currentTunnel.server.on('listening', () => {
eventHandler.onTunnelConnected(currentTunnel.server);
resolve(currentTunnel.server);
});
currentTunnel.server.on('error', error => {
currentTunnel = {};
reject(error);
});
currentTunnel.server.on('close', () => {
currentTunnel = {};
});
});
}
const sshPromise = new bluebird((resolve, reject) => {
tunnelssh(config, function (error, server) {
const listenAddress = server.address();
console.log('ssh tunnel listening in', listenAddress);
server.on('error', (error) => {
alert('SSH Connection Error: ' + error.message);
reject(error);
});
const client = redis.createClient(listenAddress.port, listenAddress.address, options);
if (error) {
reject(error);
}
else {
resolve(client);
}
let getDB = async () => {
try {
server = await tunnel(config.config);
let client = null;
try {
console.log("URL", config.url)
client = await MongoClient.connect(config.url, {useNewUrlParser: true});
}
catch(err){
console.log("ERROR IN DB: ", err);
}
console.log("Connected to DB successfully!");
database = client.db(config.databaseName);
users_collection = database.collection(DBCollections.USERS_COLLECTION)
}
catch(err){
connectToRemoteHost (host, cb) {
let config = {
host: host.Hostname,
dstPort: DST_PORT,
localPort: LOCAL_PORT,
username: host.User,
agent: process.env.SSH_AUTH_SOCK
}
this.tunnel = tunnel(config, (err) => {
if (err) return cb(err)
this.client = redis.createClient(config.localPort)
this.client.on('ready', () => {
cb()
})
})
}
return new Promise(function(resolve, reject) {
var tunnelPort = Math.round(Math.random()*10000);
var config = {
host: ssh_host,
srcPort: tunnelPort,
dstPort: ssh_port,
username: ssh_username,
password: ssh_password
};
var server = tunnel(config)
.then(function (result) {
resolve(_this.getDirectConnection(mysql_host, tunnelPort, mysql_user, mysql_password, mysql_database));
})
.catch(function (err) {
reject(err);
})
});
},