mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-28 17:48:50 +00:00
Implement stdin support for key add command
This commit is contained in:
parent
a8678f419b
commit
893d836937
@ -39,15 +39,18 @@ exports.add = permissions.user (params) ->
|
||||
async.waterfall [
|
||||
|
||||
(callback) ->
|
||||
fs.readFile(params.path, encoding: 'utf8', callback)
|
||||
if params.path?
|
||||
fs.readFile(params.path, encoding: 'utf8', callback)
|
||||
else
|
||||
helpers.readStdin(callback)
|
||||
|
||||
(contents, callback) ->
|
||||
contents = contents.trim()
|
||||
(key, callback) ->
|
||||
key = key.trim()
|
||||
|
||||
url = resin.settings.get('urls.keys')
|
||||
data =
|
||||
title: params.name
|
||||
key: contents
|
||||
key: key
|
||||
resin.server.post(url, data, callback)
|
||||
|
||||
], (error) ->
|
||||
|
@ -288,9 +288,20 @@ capitano.command
|
||||
'''
|
||||
action: actions.keys.list
|
||||
|
||||
# TODO: Write help page for this command
|
||||
capitano.command
|
||||
signature: 'key add <name> <path>'
|
||||
signature: 'key add <name> [path]'
|
||||
description: 'add a SSH key to resin.io'
|
||||
help: '''
|
||||
Use this command to associate a new SSH key with your account.
|
||||
|
||||
If `path` is omitted, the command will attempt
|
||||
to read the SSH key from stdin.
|
||||
|
||||
Examples:
|
||||
$ resin key add Main ~/.ssh/id_rsa.pub
|
||||
$ cat ~/.ssh/id_rsa.pub | resin key add Main
|
||||
'''
|
||||
action: actions.keys.add
|
||||
|
||||
capitano.command
|
||||
|
@ -6,3 +6,21 @@ exports.isDeviceUUIDValid = (uuid, callback) ->
|
||||
return callback?(error) if error?
|
||||
uuidExists = _.findWhere(devices, { uuid })?
|
||||
return callback(null, uuidExists)
|
||||
|
||||
# TODO: Find a sane way to test streams
|
||||
exports.readStdin = (callback) ->
|
||||
stdin = process.stdin
|
||||
|
||||
stdin.resume()
|
||||
stdin.setEncoding('utf8')
|
||||
|
||||
result = []
|
||||
|
||||
stdin.on('error', callback)
|
||||
|
||||
stdin.on 'data', (chunk) ->
|
||||
result.push(chunk)
|
||||
|
||||
stdin.on 'end', ->
|
||||
result = result.join()
|
||||
return callback(null, result)
|
||||
|
Loading…
Reference in New Issue
Block a user