Skip to content

Commit

Permalink
Auto-merge for PR #737 via VersionBot
Browse files Browse the repository at this point in the history
Add ssh option for direct host OS access
  • Loading branch information
resin-io-versionbot[bot] committed Dec 19, 2017
2 parents fdd253f + 15b877f commit 7433920
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v6.12.0 - 2017-12-19

* Add ssh option for direct host OS access #737 [Andreas Fitzek]

## v6.11.0 - 2017-12-18

* Fix docs generation when building on windows #729 [Tim Perry]
Expand Down
5 changes: 5 additions & 0 deletions doc/cli.markdown
Expand Up @@ -808,6 +808,7 @@ Examples:
$ resin ssh 7cf02a6
$ resin ssh 7cf02a6 --port 8080
$ resin ssh 7cf02a6 -v
$ resin ssh 7cf02a6 -s

### Options

Expand All @@ -819,6 +820,10 @@ ssh gateway port

increase verbosity

#### --host, -s

access host OS (for devices with Resin OS >= 2.7.5)

#### --noproxy

don't use the proxy configuration for this connection. Only makes sense if you've configured proxy globally.
Expand Down
6 changes: 6 additions & 0 deletions lib/actions/command-options.coffee
Expand Up @@ -98,3 +98,9 @@ exports.advancedConfig =
description: 'show advanced configuration options'
boolean: true
alias: 'v'

exports.hostOSAccess =
signature: 'host'
boolean: true
description: 'access host OS (for devices with Resin OS >= 2.7.5)'
alias: 's'
12 changes: 7 additions & 5 deletions lib/actions/local/ssh.coffee
Expand Up @@ -14,6 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
###

{ hostOSAccess } = require('../command-options')
_ = require('lodash')

localHostOSAccessOption = _.cloneDeep(hostOSAccess)
localHostOSAccessOption.description = 'get a shell into the host OS'

module.exports =
signature: 'local ssh [deviceIp]'
description: 'Get a shell into a resinOS device'
Expand Down Expand Up @@ -43,11 +49,7 @@ module.exports =
description: 'increase verbosity'
alias: 'v'
,
signature: 'host'
boolean: true
description: 'get a shell into the host OS'
alias: 's'
,
localHostOSAccessOption,
signature: 'container'
parameter: 'container'
default: null
Expand Down
15 changes: 12 additions & 3 deletions lib/actions/ssh.coffee
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
###

commandOptions = require('./command-options')

module.exports =
signature: 'ssh [uuid]'
description: '(beta) get a shell into the running app container of a device'
Expand All @@ -31,6 +33,7 @@ module.exports =
$ resin ssh 7cf02a6
$ resin ssh 7cf02a6 --port 8080
$ resin ssh 7cf02a6 -v
$ resin ssh 7cf02a6 -s
'''
permission: 'user'
primary: true
Expand All @@ -44,7 +47,7 @@ module.exports =
boolean: true
description: 'increase verbosity'
alias: 'v'
,
commandOptions.hostOSAccess,
signature: 'noproxy'
boolean: true
description: "don't use the proxy configuration for this connection.
Expand Down Expand Up @@ -109,20 +112,26 @@ module.exports =
username: resin.auth.whoami()
uuid: device.uuid
# get full uuid
containerId: resin.models.device.getApplicationInfo(device.uuid).get('containerId')
containerId: if options.host then '' else resin.models.device.getApplicationInfo(device.uuid).get('containerId')
proxyUrl: resin.settings.get('proxyUrl')

hasTunnelBin: if useProxy then hasbin('proxytunnel') else null
.then ({ username, uuid, containerId, proxyUrl, hasTunnelBin }) ->
throw new Error('Did not find running application container') if not containerId?
Promise.try ->
sshProxyCommand = getSshProxyCommand(hasTunnelBin)

if options.host
accessCommand = "host #{uuid}"
else
accessCommand = "enter #{uuid} #{containerId}"

command = "ssh #{verbose} -t \
-o LogLevel=ERROR \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
#{sshProxyCommand} \
-p #{options.port} #{username}@ssh.#{proxyUrl} enter #{uuid} #{containerId}"
-p #{options.port} #{username}@ssh.#{proxyUrl} #{accessCommand}"

subShellCommand = getSubShellCommand(command)
child_process.spawn subShellCommand.program, subShellCommand.args,
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "resin-cli",
"version": "6.11.0",
"version": "6.12.0",
"description": "The official resin.io CLI tool",
"main": "./build/actions/index.js",
"homepage": "https://github.com/resin-io/resin-cli",
Expand Down

0 comments on commit 7433920

Please sign in to comment.