mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-08 12:01:14 +00:00
Implement key add command
This commit is contained in:
parent
ff152c987d
commit
006f3e8aca
@ -1,5 +1,7 @@
|
|||||||
_ = require('lodash')
|
_ = require('lodash')
|
||||||
_.str = require('underscore.string')
|
_.str = require('underscore.string')
|
||||||
|
async = require('async')
|
||||||
|
fs = require('fs')
|
||||||
resin = require('../resin')
|
resin = require('../resin')
|
||||||
helpers = require('../helpers/helpers')
|
helpers = require('../helpers/helpers')
|
||||||
ui = require('../ui')
|
ui = require('../ui')
|
||||||
@ -32,3 +34,32 @@ exports.remove = permissions.user (params, options) ->
|
|||||||
url = _.template(resin.settings.get('urls.sshKey'), id: params.id)
|
url = _.template(resin.settings.get('urls.sshKey'), id: params.id)
|
||||||
resin.server.delete(url, callback)
|
resin.server.delete(url, callback)
|
||||||
, resin.errors.handle
|
, resin.errors.handle
|
||||||
|
|
||||||
|
exports.add = permissions.user (params) ->
|
||||||
|
async.waterfall [
|
||||||
|
|
||||||
|
(callback) ->
|
||||||
|
fs.readFile(params.path, encoding: 'utf8', callback)
|
||||||
|
|
||||||
|
(contents, callback) ->
|
||||||
|
contents = contents.trim()
|
||||||
|
|
||||||
|
url = resin.settings.get('urls.keys')
|
||||||
|
data =
|
||||||
|
title: params.name
|
||||||
|
key: contents
|
||||||
|
resin.server.post(url, data, callback)
|
||||||
|
|
||||||
|
], (error) ->
|
||||||
|
return if not error?
|
||||||
|
|
||||||
|
# TODO: Make handle() check the error type
|
||||||
|
# and accomodate as most as possible to prevent
|
||||||
|
# this types of checks in client code.
|
||||||
|
if error.code is 'EISDIR'
|
||||||
|
error.message = "File is a directory: #{params.path}"
|
||||||
|
|
||||||
|
if error.code is 'ENOENT'
|
||||||
|
error = new resin.errors.FileNotFound(params.path)
|
||||||
|
|
||||||
|
resin.errors.handle(error)
|
||||||
|
@ -276,6 +276,11 @@ capitano.command
|
|||||||
'''
|
'''
|
||||||
action: actions.keys.list
|
action: actions.keys.list
|
||||||
|
|
||||||
|
capitano.command
|
||||||
|
signature: 'key add <name> <path>'
|
||||||
|
description: 'add a SSH key to resin.io'
|
||||||
|
action: actions.keys.add
|
||||||
|
|
||||||
capitano.command
|
capitano.command
|
||||||
signature: 'key <id>'
|
signature: 'key <id>'
|
||||||
description: 'list a single ssh key'
|
description: 'list a single ssh key'
|
||||||
|
@ -110,6 +110,22 @@ exports.NotAny = class NotAny extends TypedError
|
|||||||
# Error code
|
# Error code
|
||||||
code: 0
|
code: 0
|
||||||
|
|
||||||
|
exports.FileNotFound = class FileNotFound extends TypedError
|
||||||
|
|
||||||
|
# Construct an File Not Found error
|
||||||
|
#
|
||||||
|
# @param {String} filename name of the file that was not found
|
||||||
|
#
|
||||||
|
# @example File Not Found error
|
||||||
|
# throw new resin.errors.FileNotFound('/foo')
|
||||||
|
# Error: File not found: /foo
|
||||||
|
#
|
||||||
|
constructor: (filename) ->
|
||||||
|
@message = "File not found: #{filename}"
|
||||||
|
|
||||||
|
# Error code
|
||||||
|
code: 1
|
||||||
|
|
||||||
# Handle error instances
|
# Handle error instances
|
||||||
#
|
#
|
||||||
# Prints the message to stderr and aborts the program with the corresponding error code, or 0 if none.
|
# Prints the message to stderr and aborts the program with the corresponding error code, or 0 if none.
|
||||||
|
@ -73,6 +73,6 @@
|
|||||||
"conf.js": "~0.1.1",
|
"conf.js": "~0.1.1",
|
||||||
"coffee-script": "~1.8.0",
|
"coffee-script": "~1.8.0",
|
||||||
"git-cli": "~0.8.2",
|
"git-cli": "~0.8.2",
|
||||||
"capitano": "~1.0.0"
|
"capitano": "~1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user