2015-08-26 07:40:32 +03:00
|
|
|
/*
|
2015-09-04 21:12:20 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Joyent, Inc.
|
2015-08-26 07:40:32 +03:00
|
|
|
*
|
2015-11-04 01:40:59 +02:00
|
|
|
* `triton keys ...`
|
2015-08-26 07:40:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
var common = require('./common');
|
2015-11-06 01:13:14 +02:00
|
|
|
var errors = require('./errors');
|
2015-08-26 07:40:32 +03:00
|
|
|
|
2015-11-06 01:13:14 +02:00
|
|
|
|
|
|
|
function do_keys(subcmd, opts, args, cb) {
|
2015-08-26 07:40:32 +03:00
|
|
|
if (opts.help) {
|
2015-11-06 01:13:14 +02:00
|
|
|
this.do_help('help', {}, [subcmd], cb);
|
2015-08-26 07:40:32 +03:00
|
|
|
return;
|
|
|
|
} else if (args.length !== 0) {
|
2015-11-06 01:13:14 +02:00
|
|
|
cb(new errors.UsageError('invalid args: ' + args));
|
2015-08-26 07:40:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-04 21:04:45 +03:00
|
|
|
this.tritonapi.cloudapi.listKeys(function (err, keys) {
|
2015-08-26 07:40:32 +03:00
|
|
|
if (err) {
|
2015-11-06 01:13:14 +02:00
|
|
|
cb(err);
|
2015-08-26 07:40:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.json) {
|
2015-08-26 23:53:23 +03:00
|
|
|
common.jsonStream(keys);
|
2015-08-26 07:40:32 +03:00
|
|
|
} else {
|
|
|
|
keys.forEach(function (key) {
|
2015-11-06 01:13:14 +02:00
|
|
|
console.log(common.chomp(key.key));
|
2015-08-26 07:40:32 +03:00
|
|
|
});
|
|
|
|
}
|
2015-11-06 01:13:14 +02:00
|
|
|
cb();
|
2015-08-26 07:40:32 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_keys.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['json', 'j'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'JSON output.'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
do_keys.help = (
|
2015-11-05 22:41:56 +02:00
|
|
|
'Show account SSH keys.\n'
|
2015-08-26 07:40:32 +03:00
|
|
|
+ '\n'
|
|
|
|
+ 'Usage:\n'
|
2015-11-05 22:41:56 +02:00
|
|
|
+ ' {{name}} keys [<options>]\n'
|
2015-08-26 07:40:32 +03:00
|
|
|
+ '\n'
|
|
|
|
+ '{{options}}'
|
2015-11-05 22:41:56 +02:00
|
|
|
+ '\n'
|
|
|
|
+ 'By default this lists just the key content for each key -- in other\n'
|
|
|
|
+ 'words, content appropriate for a "~/.ssh/authorized_keys" file.\n'
|
|
|
|
+ 'Use `triton keys -j` to see all fields.\n'
|
2015-08-26 07:40:32 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
module.exports = do_keys;
|