This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/lib/do_keys.js

69 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

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
*
* `triton keys ...`
2015-08-26 07:40:32 +03:00
*/
var common = require('./common');
var errors = require('./errors');
2015-08-26 07:40:32 +03:00
function do_keys(subcmd, opts, args, cb) {
2015-08-26 07:40:32 +03:00
if (opts.help) {
this.do_help('help', {}, [subcmd], cb);
2015-08-26 07:40:32 +03:00
return;
} else if (args.length !== 0) {
cb(new errors.UsageError('invalid args: ' + args));
2015-08-26 07:40:32 +03:00
return;
}
this.tritonapi.cloudapi.listKeys(function (err, keys) {
2015-08-26 07:40:32 +03:00
if (err) {
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) {
console.log(common.chomp(key.key));
2015-08-26 07:40:32 +03: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 = (
'Show account SSH keys.\n'
2015-08-26 07:40:32 +03:00
+ '\n'
+ 'Usage:\n'
+ ' {{name}} keys [<options>]\n'
2015-08-26 07:40:32 +03:00
+ '\n'
+ '{{options}}'
+ '\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;