mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-29 18:18:50 +00:00
30 lines
1.0 KiB
CoffeeScript
30 lines
1.0 KiB
CoffeeScript
_ = 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 ->
|
|
server.get config.urls.keys, (error, response, keys) ->
|
|
throw error if error?
|
|
console.log table.horizontal keys, (key) ->
|
|
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' ]))
|