mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-03-22 03:55:19 +00:00
Implement key info command
This commit is contained in:
parent
5bbbc93d80
commit
4b20ba435d
@ -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' ]))
|
||||
|
@ -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?
|
||||
|
@ -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
5
lib/models/key.coffee
Normal file
@ -0,0 +1,5 @@
|
||||
canvas = require('./_canvas')
|
||||
|
||||
exports.getAll = ->
|
||||
return canvas.get
|
||||
resource: 'user__has__public_key'
|
Loading…
x
Reference in New Issue
Block a user