2015-08-26 01:10:13 +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 01:10:13 +03:00
|
|
|
*
|
2016-01-04 19:05:53 +02:00
|
|
|
* `triton instance audit ...`
|
2015-08-26 01:10:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
var format = require('util').format;
|
|
|
|
var tabula = require('tabula');
|
|
|
|
|
2016-01-04 19:05:53 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var errors = require('../errors');
|
2015-08-26 01:10:13 +03:00
|
|
|
|
2015-09-08 19:41:31 +03:00
|
|
|
// columns default without -o
|
2015-09-09 00:30:08 +03:00
|
|
|
var columnsDefault = 'shortid,time,action,success';
|
|
|
|
|
|
|
|
// columns default with -l
|
|
|
|
var columnsDefaultLong = 'id,time,action,success';
|
2015-09-08 19:41:31 +03:00
|
|
|
|
|
|
|
// sort default with -s
|
|
|
|
var sortDefault = 'id,time';
|
|
|
|
|
2016-01-04 19:05:53 +02:00
|
|
|
|
|
|
|
function do_audit(subcmd, opts, args, cb) {
|
2015-08-26 01:10:13 +03:00
|
|
|
if (opts.help) {
|
2015-09-08 19:41:31 +03:00
|
|
|
this.do_help('help', {}, [subcmd], cb);
|
2015-08-26 01:10:13 +03:00
|
|
|
return;
|
2016-06-09 00:13:16 +03:00
|
|
|
} else if (args.length === 0) {
|
|
|
|
cb(new errors.UsageError('missing INST argument'));
|
|
|
|
return;
|
|
|
|
} else if (args.length > 1) {
|
|
|
|
cb(new errors.UsageError('too many arguments: ' + args));
|
|
|
|
return;
|
2015-09-08 19:41:31 +03:00
|
|
|
}
|
|
|
|
|
2015-09-09 00:30:08 +03:00
|
|
|
var columns = columnsDefault;
|
|
|
|
if (opts.o) {
|
|
|
|
columns = opts.o;
|
|
|
|
} else if (opts.long) {
|
|
|
|
columns = columnsDefaultLong;
|
|
|
|
}
|
|
|
|
columns = columns.split(',');
|
|
|
|
|
2015-09-08 19:41:31 +03:00
|
|
|
var sort = opts.s.split(',');
|
|
|
|
|
|
|
|
var arg = args[0];
|
|
|
|
var uuid;
|
2016-12-13 20:04:41 +02:00
|
|
|
var tritonapi = this.top.tritonapi;
|
2015-09-08 19:41:31 +03:00
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
|
|
|
|
if (common.isUUID(arg)) {
|
|
|
|
uuid = arg;
|
2015-09-08 19:41:31 +03:00
|
|
|
go1();
|
2016-12-13 20:04:41 +02:00
|
|
|
} else {
|
|
|
|
tritonapi.getInstance(arg, function (err, inst) {
|
|
|
|
if (err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uuid = inst.id;
|
|
|
|
go1();
|
|
|
|
});
|
|
|
|
}});
|
2015-08-26 01:10:13 +03:00
|
|
|
|
2015-09-08 19:41:31 +03:00
|
|
|
function go1() {
|
2016-12-13 20:04:41 +02:00
|
|
|
tritonapi.cloudapi.machineAudit(uuid, function (err, audit) {
|
2015-09-08 19:41:31 +03:00
|
|
|
if (err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
audit.forEach(function (a) {
|
|
|
|
a.id = uuid;
|
2015-09-09 00:30:08 +03:00
|
|
|
a.shortid = common.uuidToShortId(uuid);
|
2015-09-08 19:41:31 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (opts.json) {
|
|
|
|
common.jsonStream(audit);
|
|
|
|
} else {
|
|
|
|
tabula(audit, {
|
|
|
|
skipHeader: opts.H,
|
|
|
|
columns: columns,
|
|
|
|
sort: sort,
|
|
|
|
dottedLookup: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
}
|
2015-09-01 19:00:45 +03:00
|
|
|
}
|
|
|
|
|
2016-01-04 19:05:53 +02:00
|
|
|
do_audit.options = [
|
2015-08-26 01:10:13 +03:00
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
}
|
2015-09-08 19:41:31 +03:00
|
|
|
].concat(common.getCliTableOptions({
|
2015-09-09 00:30:08 +03:00
|
|
|
includeLong: true,
|
2015-09-08 19:41:31 +03:00
|
|
|
sortDefault: sortDefault
|
|
|
|
}));
|
|
|
|
|
2016-06-09 00:13:16 +03:00
|
|
|
do_audit.synopses = ['{{name}} {{cmd}} [OPTIONS] INST'];
|
|
|
|
do_audit.help = [
|
|
|
|
'List instance actions.',
|
|
|
|
'',
|
|
|
|
'{{usage}}',
|
|
|
|
'',
|
|
|
|
'{{options}}',
|
|
|
|
'Where "INST" is an instance name, id, or short id.'
|
|
|
|
].join('\n');
|
2015-08-26 01:10:13 +03:00
|
|
|
|
2016-03-09 19:19:44 +02:00
|
|
|
do_audit.completionArgtypes = ['tritoninstance', 'none'];
|
|
|
|
|
2016-01-04 19:05:53 +02:00
|
|
|
module.exports = do_audit;
|