Skip to content
This repository was archived by the owner on Mar 18, 2018. It is now read-only.
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
11 changes: 11 additions & 0 deletions lib/ssh/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var isFunction = require('lodash').isFunction;
var extend = require('lodash').extend;
var async = require('async');
var Connection = require('./connection');
var extend = require('lodash').extend;

/**
* Expose ConnectionPool.
Expand All @@ -24,6 +25,16 @@ function ConnectionPool(connections, options) {
// Create connection if necessary.
connections = connections.map(function (connection) {
if (connection instanceof Connection) return connection;

var splitURL = connection.split(':');
var port = 22;

if (splitURL[1]) {
connection = splitURL[0];
port = splitURL[1];
}

options = extend(options || {}, {port: port});
return new Connection(extend({ remote: connection }, options));
});

Expand Down
3 changes: 2 additions & 1 deletion lib/ssh/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Connection.prototype.run = function (command, options, cb) {

// In sudo mode, we use a TTY channel.
var args = /^sudo/.exec(command) ? ['-tt'] : [];
args.push('-p ' + (this.options.port || 22));
args.push(remote.format(this.remote));

// Escape double quotes in command.
Expand Down Expand Up @@ -101,7 +102,7 @@ Connection.prototype.copy = function (src, dest, options, cb) {
var args = ['rsync'].concat(excludes).concat([
'-az',
'-e',
'ssh',
'"ssh -p ' + (this.options.port || 22) + '"',
src,
dest
]);
Expand Down
14 changes: 7 additions & 7 deletions test/unit/ssh/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('SSH Connection', function () {
connection.run('my-command -x', { cwd: '/root' }, done);

expect(childProcess.exec).to.be.calledWith(
'ssh user@host "my-command -x"',
'ssh -p 22 user@host "my-command -x"',
{ cwd: '/root', maxBuffer: 1000 * 1024 }
);
});
Expand All @@ -66,7 +66,7 @@ describe('SSH Connection', function () {
connection.run('echo "ok"', {cwd: '/root'}, done);

expect(childProcess.exec).to.be.calledWith(
'ssh user@host "echo \\"ok\\""',
'ssh -p 22 user@host "echo \\"ok\\""',
{ cwd: '/root', maxBuffer: 1000 * 1024 }
);
});
Expand All @@ -84,7 +84,7 @@ describe('SSH Connection', function () {
connection.run('sudo my-command -x', { cwd: '/root' }, done);

expect(childProcess.exec).to.be.calledWith(
'ssh -tt user@host "sudo my-command -x"',
'ssh -tt -p 22 user@host "sudo my-command -x"',
{ cwd: '/root', maxBuffer: 1000 * 1024 }
);
});
Expand All @@ -94,11 +94,11 @@ describe('SSH Connection', function () {
connection.run('my-command2 -x', function () {});

expect(childProcess.exec).to.be.calledWith(
'ssh user@host "my-command -x"'
'ssh -p 22 user@host "my-command -x"'
);

expect(childProcess.exec).to.be.calledWith(
'ssh user@host "my-command2 -x"'
'ssh -p 22 user@host "my-command2 -x"'
);
});
});
Expand All @@ -116,14 +116,14 @@ describe('SSH Connection', function () {
it('should call cmd.spawn', function (done) {
connection.copy('/src/dir', '/dest/dir', done);

expect(childProcess.exec).to.be.calledWith('rsync -az -e ssh /src/dir user@host:/dest/dir');
expect(childProcess.exec).to.be.calledWith('rsync -az -e "ssh -p 22" /src/dir user@host:/dest/dir');
});

it('should accept "ignores" option', function (done) {
connection.copy('/src/dir', '/dest/dir', { ignores: ['a', 'b'] }, done);

expect(childProcess.exec).to.be.calledWith('rsync --exclude a --exclude b -az -e ' +
'ssh /src/dir user@host:/dest/dir');
'"ssh -p 22" /src/dir user@host:/dest/dir');
});
});
});