2015-11-06 01:21:19 +02: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.
|
|
|
|
*
|
|
|
|
* `triton rbac keys ...`
|
|
|
|
*/
|
|
|
|
|
2015-11-21 22:41:16 +02:00
|
|
|
var tabula = require('tabula');
|
|
|
|
|
2015-11-06 01:21:19 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var errors = require('../errors');
|
|
|
|
|
|
|
|
|
2015-11-21 22:41:16 +02:00
|
|
|
var columnsDefault = 'fingerprint,name';
|
|
|
|
var columnsDefaultLong = 'fingerprint,name,key';
|
|
|
|
var sortDefault = 'name';
|
|
|
|
|
2015-11-06 01:21:19 +02:00
|
|
|
|
|
|
|
function do_keys(subcmd, opts, args, cb) {
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], cb);
|
|
|
|
return;
|
|
|
|
} else if (args.length === 0) {
|
|
|
|
cb(new errors.UsageError('no USER argument given'));
|
|
|
|
return;
|
|
|
|
} else if (args.length !== 1) {
|
|
|
|
cb(new errors.UsageError('invalid args: ' + args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-21 22:41:16 +02:00
|
|
|
var columns = columnsDefault;
|
|
|
|
if (opts.o) {
|
|
|
|
columns = opts.o;
|
|
|
|
} else if (opts.long) {
|
|
|
|
columns = columnsDefaultLong;
|
|
|
|
}
|
|
|
|
columns = columns.split(',');
|
|
|
|
var sort = opts.s.split(',');
|
|
|
|
|
2015-11-06 01:21:19 +02:00
|
|
|
this.top.tritonapi.cloudapi.listUserKeys({userId: args[0]},
|
|
|
|
function (err, userKeys) {
|
|
|
|
if (err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.json) {
|
|
|
|
common.jsonStream(userKeys);
|
2015-11-21 22:41:16 +02:00
|
|
|
} else if (opts.authorized_keys) {
|
2015-11-06 01:21:19 +02:00
|
|
|
userKeys.forEach(function (key) {
|
|
|
|
console.log(common.chomp(key.key));
|
|
|
|
});
|
2015-11-21 22:41:16 +02:00
|
|
|
} else {
|
|
|
|
tabula(userKeys, {
|
|
|
|
skipHeader: false,
|
|
|
|
columns: columns,
|
|
|
|
sort: sort
|
|
|
|
});
|
2015-11-06 01:21:19 +02:00
|
|
|
}
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_keys.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
2015-11-21 22:41:16 +02:00
|
|
|
}
|
|
|
|
].concat(common.getCliTableOptions({
|
|
|
|
includeLong: true,
|
|
|
|
sortDefault: sortDefault
|
|
|
|
})).concat([
|
2015-11-06 01:21:19 +02:00
|
|
|
{
|
2015-11-21 22:41:16 +02:00
|
|
|
names: ['authorized-keys', 'A'],
|
2015-11-06 01:21:19 +02:00
|
|
|
type: 'bool',
|
2015-11-21 22:41:16 +02:00
|
|
|
help: 'Just output public key data -- i.e. output appropriate for a ' +
|
|
|
|
'"~/.ssh/authorized_keys" file.'
|
2015-11-06 01:21:19 +02:00
|
|
|
}
|
2015-11-21 22:41:16 +02:00
|
|
|
]);
|
2015-11-06 01:21:19 +02:00
|
|
|
|
|
|
|
do_keys.help = (
|
|
|
|
/* BEGIN JSSTYLED */
|
|
|
|
'List RBAC user SSH keys.\n' +
|
|
|
|
'\n' +
|
|
|
|
'Usage:\n' +
|
|
|
|
' {{name}} keys [<options>] USER\n' +
|
|
|
|
'\n' +
|
|
|
|
'{{options}}' +
|
|
|
|
'\n' +
|
2015-11-21 22:41:16 +02:00
|
|
|
'Where "USER" is an RBAC user login or id (a UUID).\n'
|
2015-11-06 01:21:19 +02:00
|
|
|
/* END JSSTYLED */
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = do_keys;
|