2014-11-20 18:00:39 +00:00
|
|
|
_ = require('lodash')
|
2014-11-26 16:07:10 +00:00
|
|
|
resin = require('../resin')
|
2014-11-20 18:00:39 +00:00
|
|
|
helpers = require('../helpers/helpers')
|
2014-11-20 17:02:29 +00:00
|
|
|
|
2014-11-27 14:06:11 +00:00
|
|
|
exports.list = ->
|
2014-11-26 17:42:05 +00:00
|
|
|
resin.server.get resin.config.urls.keys, (error, response, keys) ->
|
2014-11-26 16:38:02 +00:00
|
|
|
resin.errors.handle(error) if error?
|
2014-11-26 17:26:01 +00:00
|
|
|
resin.log.out resin.ui.widgets.table.horizontal keys, (key) ->
|
2014-11-20 17:02:29 +00:00
|
|
|
delete key.public_key
|
|
|
|
return key
|
|
|
|
, [ 'ID', 'Title' ]
|
2014-11-20 18:00:39 +00:00
|
|
|
|
2014-11-27 14:06:11 +00:00
|
|
|
exports.info = (id) ->
|
2014-11-21 13:23:02 +00:00
|
|
|
id = _.parseInt(id)
|
2014-11-20 18:00:39 +00:00
|
|
|
|
|
|
|
# TODO: We don't have a way to query a single ssh key yet.
|
|
|
|
# As a workaround, we request all of them, and filter
|
|
|
|
# the one we need. Fix once we have a better way.
|
2014-11-26 17:42:05 +00:00
|
|
|
resin.server.get resin.config.urls.keys, (error, response, keys) ->
|
2014-11-26 16:38:02 +00:00
|
|
|
resin.errors.handle(error) if error?
|
2014-11-20 18:00:39 +00:00
|
|
|
key = _.findWhere(keys, { id })
|
|
|
|
if not key?
|
2014-11-26 16:38:02 +00:00
|
|
|
resin.errors.handle(new resin.errors.NotFound("key #{id}"))
|
2014-11-20 18:00:39 +00:00
|
|
|
|
2014-11-26 17:42:05 +00:00
|
|
|
key.public_key = '\n' + helpers.formatLongString(key.public_key, resin.config.sshKeyWidth)
|
2014-11-26 17:26:01 +00:00
|
|
|
resin.log.out(resin.ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
2014-11-21 17:56:11 +00:00
|
|
|
|
2014-11-27 15:22:48 +00:00
|
|
|
exports.remove = (id) ->
|
|
|
|
confirmArgument = resin.cli.getArgument('yes')
|
|
|
|
resin.ui.patterns.remove 'key', confirmArgument, (callback) ->
|
2014-11-26 16:07:10 +00:00
|
|
|
resin.server.delete("/user/keys/#{id}", callback)
|
2014-11-26 16:38:02 +00:00
|
|
|
, resin.errors.handle
|