From b4439b7d789acc7e85ed1a76d67885db0df5b12d Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Mon, 11 Mar 2019 18:54:22 +0000 Subject: [PATCH] ssh: add `--noninteractive` flag not to suggest devices to connect to The suggestion happens if the UUID supplied is not found. Because of that function, it's impossible to do an atomic connect to a device in non-interactive mode. The auto-suggestion results connecting to the first available device, which is likely not the intended action. The current workaround is running a `balena device UUID` and check its exit code before running `balena ssh UUID`, but since these are independent steps, still can connect to another device, if between the two commands anything changes. With this flag used, one could never connect accidentally to the wrong device due to suggestions. Change-type: minor Signed-off-by: Gergely Imreh --- doc/cli.markdown | 5 +++++ lib/actions/ssh.coffee | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/cli.markdown b/doc/cli.markdown index eea84411..09efba6e 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -975,6 +975,7 @@ Examples: $ balena ssh 7cf02a6 --port 8080 $ balena ssh 7cf02a6 -v $ balena ssh 7cf02a6 -s + $ balena ssh 7cf02a6 --noninteractive ### Options @@ -994,6 +995,10 @@ access host OS (for devices with balenaOS >= 2.0.0+rev1) don't use the proxy configuration for this connection. Only makes sense if you've configured proxy globally. +#### --noninteractive + +run command non-interactively, do not automatically suggest devices to connect to if UUID not found + # Notes ## note <|note> diff --git a/lib/actions/ssh.coffee b/lib/actions/ssh.coffee index 0074f198..3ea802d4 100644 --- a/lib/actions/ssh.coffee +++ b/lib/actions/ssh.coffee @@ -35,6 +35,7 @@ module.exports = $ balena ssh 7cf02a6 --port 8080 $ balena ssh 7cf02a6 -v $ balena ssh 7cf02a6 -s + $ balena ssh 7cf02a6 --noninteractive ''' permission: 'user' primary: true @@ -53,6 +54,10 @@ module.exports = boolean: true description: "don't use the proxy configuration for this connection. Only makes sense if you've configured proxy globally." + , + signature: 'noninteractive' + boolean: true + description: 'run command non-interactively, do not automatically suggest devices to connect to if UUID not found' ] action: (params, options, done) -> normalizeUuidProp(params) @@ -103,6 +108,9 @@ module.exports = return balena.models.device.has(params.uuid) .then (uuidExists) -> return params.uuid if uuidExists + if options.noninteractive + console.error("Could not find device: #{params.uuid}") + process.exit(1) return patterns.inferOrSelectDevice() .then (uuid) -> console.info("Connecting to: #{uuid}")