2014-11-20 18:00:39 +00:00
|
|
|
_ = require('lodash')
|
2014-12-09 18:35:45 +00:00
|
|
|
_.str = require('underscore.string')
|
2014-12-19 17:06:58 +00:00
|
|
|
async = require('async')
|
|
|
|
fs = require('fs')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2014-11-20 18:00:39 +00:00
|
|
|
helpers = require('../helpers/helpers')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-12-22 16:41:14 +00:00
|
|
|
log = require('../log/log')
|
2014-12-12 21:20:29 +00:00
|
|
|
permissions = require('../permissions/permissions')
|
2014-12-22 16:47:12 +00:00
|
|
|
errors = require('../errors/errors')
|
2014-11-20 17:02:29 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.list = permissions.user ->
|
2015-01-09 15:22:18 +00:00
|
|
|
resin.models.key.getAll errors.handleCallback (keys) ->
|
2015-01-06 17:12:11 +00:00
|
|
|
log.out ui.widgets.table.horizontal keys, [ 'ID', 'Title' ]
|
2014-11-20 18:00:39 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.info = permissions.user (params) ->
|
2015-01-09 15:22:18 +00:00
|
|
|
resin.models.key.get params.id, errors.handleCallback (key) ->
|
2014-12-12 21:20:29 +00:00
|
|
|
key.public_key = '\n' + _.str.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
|
2015-01-06 17:12:11 +00:00
|
|
|
log.out(ui.widgets.table.vertical(key, [ 'ID', 'Title', 'Public Key' ]))
|
2014-11-21 17:56:11 +00:00
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
exports.remove = permissions.user (params, options) ->
|
|
|
|
ui.patterns.remove 'key', options.yes, (callback) ->
|
2014-12-22 19:18:47 +00:00
|
|
|
resin.models.key.remove(params.id, callback)
|
2014-12-22 16:47:12 +00:00
|
|
|
, errors.handle
|
2014-12-19 17:06:58 +00:00
|
|
|
|
|
|
|
exports.add = permissions.user (params) ->
|
|
|
|
async.waterfall [
|
|
|
|
|
|
|
|
(callback) ->
|
2014-12-22 14:30:21 +00:00
|
|
|
if params.path?
|
|
|
|
fs.readFile(params.path, encoding: 'utf8', callback)
|
|
|
|
else
|
|
|
|
helpers.readStdin(callback)
|
2014-12-19 17:06:58 +00:00
|
|
|
|
2014-12-22 14:30:21 +00:00
|
|
|
(key, callback) ->
|
2014-12-22 19:18:47 +00:00
|
|
|
resin.models.key.create(params.name, key, callback)
|
2014-12-19 17:06:58 +00:00
|
|
|
|
2015-01-06 16:54:40 +00:00
|
|
|
], errors.handle
|