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_instance/do_audit.js

117 lines
2.6 KiB
JavaScript
Raw Normal View History

/*
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.
*
* `triton instance audit ...`
*/
var format = require('util').format;
var tabula = require('tabula');
var common = require('../common');
var errors = require('../errors');
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';
function do_audit(subcmd, opts, args, cb) {
2015-09-08 19:41:31 +03:00
var self = this;
if (opts.help) {
2015-09-08 19:41:31 +03:00
this.do_help('help', {}, [subcmd], cb);
return;
2015-09-08 19:41:31 +03:00
} else if (args.length !== 1) {
//XXX Support multiple machines.
2015-09-08 19:41:31 +03:00
return cb(new Error('incorrect args: ' + args));
}
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;
if (common.isUUID(arg)) {
uuid = arg;
go1();
} else {
self.top.tritonapi.getInstance(arg, function (err, inst) {
2015-09-08 19:41:31 +03:00
if (err) {
cb(err);
return;
}
uuid = inst.id;
go1();
});
}
2015-09-08 19:41:31 +03:00
function go1() {
self.top.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
}
do_audit.options = [
{
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
}));
do_audit.help = (
'List instance actions.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} audit <alias|id>\n'
+ '\n'
+ '{{options}}'
);
do_audit.completionArgtypes = ['tritoninstance', 'none'];
module.exports = do_audit;