2016-01-04 03:58:51 +00:00
|
|
|
###
|
2017-06-14 21:20:15 +00:00
|
|
|
Copyright 2016-2017 Resin.io
|
2016-01-04 03:58:51 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
###
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
commandOptions = require('./command-options')
|
2014-11-20 17:02:29 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.list =
|
|
|
|
signature: 'keys'
|
|
|
|
description: 'list all ssh keys'
|
|
|
|
help: '''
|
|
|
|
Use this command to list all your SSH keys.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin keys
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2017-01-25 18:32:07 +00:00
|
|
|
resin = require('resin-sdk-preconfigured')
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2015-07-22 22:06:53 +00:00
|
|
|
resin.models.key.getAll().then (keys) ->
|
2015-08-17 13:28:10 +00:00
|
|
|
console.log visuals.table.horizontal keys, [
|
|
|
|
'id'
|
|
|
|
'title'
|
|
|
|
]
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.info =
|
|
|
|
signature: 'key <id>'
|
|
|
|
description: 'list a single ssh key'
|
|
|
|
help: '''
|
|
|
|
Use this command to show information about a single SSH key.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin key 17
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2017-01-25 18:32:07 +00:00
|
|
|
resin = require('resin-sdk-preconfigured')
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2015-07-22 22:06:53 +00:00
|
|
|
resin.models.key.get(params.id).then (key) ->
|
2015-08-14 16:25:55 +00:00
|
|
|
console.log visuals.table.vertical key, [
|
|
|
|
'id'
|
|
|
|
'title'
|
|
|
|
]
|
|
|
|
|
|
|
|
# Since the public key string is long, it might
|
|
|
|
# wrap to lines below, causing the table layout to break.
|
|
|
|
# See https://github.com/resin-io/resin-cli/issues/151
|
|
|
|
console.log('\n' + key.public_key)
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.remove =
|
|
|
|
signature: 'key rm <id>'
|
|
|
|
description: 'remove a ssh key'
|
|
|
|
help: '''
|
|
|
|
Use this command to remove a SSH key from resin.io.
|
|
|
|
|
|
|
|
Notice this command asks for confirmation interactively.
|
|
|
|
You can avoid this by passing the `--yes` boolean option.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin key rm 17
|
|
|
|
$ resin key rm 17 --yes
|
|
|
|
'''
|
|
|
|
options: [ commandOptions.yes ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2017-01-25 18:32:07 +00:00
|
|
|
resin = require('resin-sdk-preconfigured')
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, 'Are you sure you want to delete the key?').then ->
|
2015-08-17 13:28:10 +00:00
|
|
|
resin.models.key.remove(params.id)
|
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.add =
|
|
|
|
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:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin key add Main ~/.ssh/id_rsa.pub
|
|
|
|
$ cat ~/.ssh/id_rsa.pub | resin key add Main
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-12-07 14:32:24 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
Promise = require('bluebird')
|
2017-03-27 09:14:55 +00:00
|
|
|
readFileAsync = Promise.promisify(require('fs').readFile)
|
2015-12-07 14:32:24 +00:00
|
|
|
capitano = require('capitano')
|
2017-01-25 18:32:07 +00:00
|
|
|
resin = require('resin-sdk-preconfigured')
|
2015-12-07 14:32:24 +00:00
|
|
|
|
2015-08-17 13:28:10 +00:00
|
|
|
Promise.try ->
|
2017-03-27 09:14:55 +00:00
|
|
|
return readFileAsync(params.path, encoding: 'utf8') if params.path?
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2017-03-27 09:14:55 +00:00
|
|
|
# TODO: should this be promisified for consistency?
|
2015-08-17 13:28:10 +00:00
|
|
|
Promise.fromNode (callback) ->
|
|
|
|
capitano.utils.getStdin (data) ->
|
|
|
|
return callback(null, data)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-17 13:28:10 +00:00
|
|
|
.then(_.partial(resin.models.key.create, params.name))
|
|
|
|
.nodeify(done)
|