Merge pull request #354 from resin-io/feature/resin-ssh-verbose

Support --verbose/-v flag in resin ssh
This commit is contained in:
Juan Cruz Viotti 2016-06-22 09:37:03 -04:00 committed by GitHub
commit c5452f9304
2 changed files with 18 additions and 4 deletions

View File

@ -37,7 +37,7 @@ limitations under the License.
module.exports = { module.exports = {
signature: 'ssh <uuid>', signature: 'ssh <uuid>',
description: '(beta) get a shell into the running app container of a device', description: '(beta) get a shell into the running app container of a device',
help: 'WARNING: If you\'re running Windows, this command only supports `cmd.exe`.\n\nUse this command to get a shell into the running application container of\nyour device.\n\nExamples:\n\n $ resin ssh 7cf02a6\n $ resin ssh 7cf02a6 --port 8080', help: 'WARNING: If you\'re running Windows, this command only supports `cmd.exe`.\n\nUse this command to get a shell into the running application container of\nyour device.\n\nExamples:\n\n $ resin ssh 7cf02a6\n $ resin ssh 7cf02a6 --port 8080\n $ resin ssh 7cf02a6 -v',
permission: 'user', permission: 'user',
primary: true, primary: true,
options: [ options: [
@ -46,10 +46,15 @@ limitations under the License.
parameter: 'port', parameter: 'port',
description: 'ssh gateway port', description: 'ssh gateway port',
alias: 't' alias: 't'
}, {
signature: 'verbose',
boolean: true,
description: 'increase verbosity',
alias: 'v'
} }
], ],
action: function(params, options, done) { action: function(params, options, done) {
var Promise, child_process, resin, settings; var Promise, child_process, resin, settings, verbose;
child_process = require('child_process'); child_process = require('child_process');
Promise = require('bluebird'); Promise = require('bluebird');
resin = require('resin-sdk'); resin = require('resin-sdk');
@ -57,6 +62,7 @@ limitations under the License.
if (options.port == null) { if (options.port == null) {
options.port = 22; options.port = 22;
} }
verbose = options.verbose ? '-vvv' : '';
console.info("Connecting with: " + params.uuid); console.info("Connecting with: " + params.uuid);
return Promise.props({ return Promise.props({
isOnline: resin.models.device.isOnline(params.uuid), isOnline: resin.models.device.isOnline(params.uuid),
@ -74,7 +80,7 @@ limitations under the License.
} }
return Promise["try"](function() { return Promise["try"](function() {
var command, spawn, subShellCommand; var command, spawn, subShellCommand;
command = "ssh -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p " + options.port + " " + username + "@ssh." + (settings.get('proxyUrl')) + " enter " + uuid + " " + containerId; command = "ssh " + verbose + " -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p " + options.port + " " + username + "@ssh." + (settings.get('proxyUrl')) + " enter " + uuid + " " + containerId;
subShellCommand = getSubShellCommand(command); subShellCommand = getSubShellCommand(command);
return spawn = child_process.spawn(subShellCommand.program, subShellCommand.args, { return spawn = child_process.spawn(subShellCommand.program, subShellCommand.args, {
stdio: 'inherit' stdio: 'inherit'

View File

@ -48,6 +48,7 @@ module.exports =
$ resin ssh 7cf02a6 $ resin ssh 7cf02a6
$ resin ssh 7cf02a6 --port 8080 $ resin ssh 7cf02a6 --port 8080
$ resin ssh 7cf02a6 -v
''' '''
permission: 'user' permission: 'user'
primary: true primary: true
@ -56,6 +57,11 @@ module.exports =
parameter: 'port' parameter: 'port'
description: 'ssh gateway port' description: 'ssh gateway port'
alias: 't' alias: 't'
,
signature: 'verbose'
boolean: true
description: 'increase verbosity'
alias: 'v'
] ]
action: (params, options, done) -> action: (params, options, done) ->
child_process = require('child_process') child_process = require('child_process')
@ -66,6 +72,8 @@ module.exports =
if not options.port? if not options.port?
options.port = 22 options.port = 22
verbose = if options.verbose then '-vvv' else ''
console.info("Connecting with: #{params.uuid}") console.info("Connecting with: #{params.uuid}")
Promise.props Promise.props
@ -77,7 +85,7 @@ module.exports =
throw new Error('Device is not online') if not isOnline throw new Error('Device is not online') if not isOnline
throw new Error('Did not find running application container') if not containerId? throw new Error('Did not find running application container') if not containerId?
Promise.try -> Promise.try ->
command = "ssh -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ command = "ssh #{verbose} -t -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-p #{options.port} #{username}@ssh.#{settings.get('proxyUrl')} enter #{uuid} #{containerId}" -p #{options.port} #{username}@ssh.#{settings.get('proxyUrl')} enter #{uuid} #{containerId}"
subShellCommand = getSubShellCommand(command) subShellCommand = getSubShellCommand(command)