add triton keys

This commit is contained in:
Dave Eddy 2015-08-26 00:40:32 -04:00
parent ba5e4d0af4
commit b2105ca41f
3 changed files with 73 additions and 0 deletions

View File

@ -61,6 +61,7 @@ function CLI() {
{ group: 'Operator Commands' }, { group: 'Operator Commands' },
'account', 'account',
'info', 'info',
'keys',
{ group: 'Instances (aka VMs/Machines/Containers)' }, { group: 'Instances (aka VMs/Machines/Containers)' },
'create-instance', 'create-instance',
'instances', 'instances',
@ -113,6 +114,7 @@ CLI.prototype.init = function (opts, args, callback) {
// Operator // Operator
CLI.prototype.do_account = require('./do_account'); CLI.prototype.do_account = require('./do_account');
CLI.prototype.do_info = require('./do_info'); CLI.prototype.do_info = require('./do_info');
CLI.prototype.do_keys = require('./do_keys');
// Images // Images
CLI.prototype.do_images = require('./do_images'); CLI.prototype.do_images = require('./do_images');

View File

@ -250,6 +250,20 @@ CloudAPI.prototype.getAccount = function getAccount(callback) {
}); });
}; };
/**
* Get public key information
*
* @param {Function} callback of the form `function (err, keys, response)`
*/
CloudAPI.prototype.listKeys = function listKeys(callback) {
var self = this;
assert.func(callback, 'callback');
var endpoint = sprintf('/%s/keys', self.user);
this._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};
// ---- images // ---- images

57
lib/do_keys.js Normal file
View File

@ -0,0 +1,57 @@
/*
* Copyright 2015 Joyent Inc.
*
* `triton account ...`
*/
var common = require('./common');
function do_keys(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 0) {
callback(new Error('invalid args: ' + args));
return;
}
this.triton.cloudapi.listKeys(function (err, keys) {
if (err) {
callback(err);
return;
}
if (opts.json) {
console.log(JSON.stringify(keys));
} else {
// pretty print
keys.forEach(function (key) {
console.log(key.key);
});
}
callback();
});
}
do_keys.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON output.'
}
];
do_keys.help = (
'Show public keys.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} keys\n'
+ '\n'
+ '{{options}}'
);
module.exports = do_keys;