Implement key info command

This commit is contained in:
Juan Cruz Viotti 2014-11-20 14:00:39 -04:00
parent 5bbbc93d80
commit 4b20ba435d
4 changed files with 24 additions and 0 deletions

View File

@ -1,6 +1,9 @@
_ = require('lodash')
server = require('../server/server')
authHooks = require('../hooks/auth')
table = require('../table/table')
helpers = require('../helpers/helpers')
keyModel = require('../models/key')
config = require('../config')
exports.list = authHooks.failIfNotLoggedIn ->
@ -10,3 +13,17 @@ exports.list = authHooks.failIfNotLoggedIn ->
delete key.public_key
return key
, [ 'ID', 'Title' ]
exports.info = authHooks.failIfNotLoggedIn (id) ->
# 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.
server.get config.urls.keys, (error, response, keys) ->
throw error if error?
key = _.findWhere(keys, { id })
if not key?
throw new Error("Key #{id} doesn't exists")
key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth)
console.log(table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))

View File

@ -35,6 +35,7 @@ yargs.command('version', version.version)
# ---------- Keys Module ----------
keys = require('./actions/keys')
yargs.command('keys', keys.list)
yargs.command('key <id>', keys.info)
data.prefix.set config.dataPrefix, (error) ->
throw error if error?

View File

@ -11,6 +11,7 @@ config =
# TODO: Check if not running on UNIX environment
# and add a custom path accordingly
dataPrefix: path.join(process.env.HOME, '.resin')
sshKeyWidth: 43
config.urls =
signup: '/signup'

5
lib/models/key.coffee Normal file
View File

@ -0,0 +1,5 @@
canvas = require('./_canvas')
exports.getAll = ->
return canvas.get
resource: 'user__has__public_key'