UNPKG

firmament-vita

Version:

Firmament module for automating VITA tasks

170 lines 8.73 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var inversify_1 = require("inversify"); var firmament_yargs_1 = require("firmament-yargs"); var inversify_config_1 = require("../inversify.config"); var _ = require('lodash'); var shorthash = require('shorthash'); var deepExtend = require('deep-extend'); var async = require('async'); var VitaTasksImpl = (function (_super) { __extends(VitaTasksImpl, _super); function VitaTasksImpl(commandUtil, vitaFileUtil, progressBar, vitaPcapMerge, vitaDecryptUnTar) { var _this = _super.call(this) || this; _this.commandUtil = commandUtil; _this.vitaFileUtil = vitaFileUtil; _this.progressBar = progressBar; _this.vitaPcapMerge = vitaPcapMerge; _this.vitaDecryptUnTar = vitaDecryptUnTar; _this.count = 0; return _this; } VitaTasksImpl_1 = VitaTasksImpl; VitaTasksImpl.prototype.jsonOut = function (argv) { var fullPipeline = inversify_config_1.default.get('FullPipeline'); fullPipeline.fromArgv(argv); if (argv.write) { fullPipeline.toJsonFile(argv.write); } else { this.commandUtil.stdoutWrite(fullPipeline.toJson()); } this.commandUtil.processExit(); }; VitaTasksImpl.hash = function (input) { var retVal = shorthash.unique(input); if (!isNaN(parseInt(retVal[0]))) { retVal = "A" + retVal; } return retVal; }; VitaTasksImpl.prototype.process = function (argv) { var _this = this; var fullPipeline = inversify_config_1.default.get('FullPipeline'); fullPipeline.fromArgv(argv); this.processFullPipelineInstance(fullPipeline, function (err, result) { if (result.decryptAndUnTarStatus) { var _a = result.decryptAndUnTarStatus, taskName = _a.taskName, current = _a.current, total = _a.total; _this.progressBar.showProgressForTask('decryptAndUnTarStatus', taskName, current, total); } else if (result.unZipFileStatus) { _this.progressBar.showProgressForTask('decryptAndUnTarStatus', '', 1, 0); var _b = result.unZipFileStatus, taskName = _b.taskName, current = _b.current, total = _b.total; _this.progressBar.showProgressForTask(VitaTasksImpl_1.hash(taskName), taskName, current, total); } else if (result.mergePcapFilesStatus) { var _c = result.mergePcapFilesStatus, taskName = _c.taskName, current = _c.current, total = _c.total; _this.progressBar.showProgressForTask(VitaTasksImpl_1.hash(taskName), taskName, current, total); } }, function (err, result) { _this.commandUtil.processExitWithError(err, JSON.stringify(result, undefined, 2)); }); }; VitaTasksImpl.prototype.processFullPipelineInstance = function (fullPipeline, cbStatus, cbFinal) { var me = this; cbStatus = me.checkCallback(cbStatus); cbFinal = me.checkCallback(cbFinal); try { var startTime_1 = new Date(); fullPipeline.validate(); var processFullPipelineResult_1 = {}; me.vitaDecryptUnTar.process(fullPipeline.decryptAndUnTarOptions, function (err, decryptAndUnTarStatus) { cbStatus(err, { tag: fullPipeline.tag, decryptAndUnTarStatus: decryptAndUnTarStatus, startTime: startTime_1, currentTime: new Date(), status: 'Decrypting ...' }); }, function (err, decryptAndUnTarResults) { processFullPipelineResult_1.decryptAndUnTarResults = decryptAndUnTarResults; if (me.commandUtil.callbackIfError(cbFinal, err, processFullPipelineResult_1)) { return; } decryptAndUnTarResults.forEach(function (result) { fullPipeline.unZipFileOptions.zippedFiles = result.zipFiles; processFullPipelineResult_1.unZipFileResults = []; me.vitaFileUtil.unZipFiles(fullPipeline.unZipFileOptions, function (err, unZipFileStatus) { cbStatus(err, { tag: fullPipeline.tag, unZipFileStatus: unZipFileStatus, startTime: startTime_1, currentTime: new Date(), status: 'Unzipping PCAP file ...' }); }, function (err, unZipFileResults) { processFullPipelineResult_1.unZipFileResults.push(unZipFileResults); if (me.commandUtil.callbackIfError(cbFinal, err)) { return; } fullPipeline.mergePcapFilesOptions.pcapFiles = unZipFileResults.map(function (unZipFileResult) { return unZipFileResult.unzippedFilePath; }).filter(function (pcapFile) { return !!pcapFile; }); me.vitaPcapMerge.mergePcapFiles(fullPipeline.mergePcapFilesOptions, function (err, mergePcapFilesStatus) { cbStatus(err, { tag: fullPipeline.tag, mergePcapFilesStatus: mergePcapFilesStatus, startTime: startTime_1, currentTime: new Date(), status: 'Merging PCAP files ...' }); }, function (err, result) { processFullPipelineResult_1.mergePcapFilesResult = result; processFullPipelineResult_1.tag = fullPipeline.tag; var finalStatus = { tag: fullPipeline.tag, startTime: startTime_1, currentTime: new Date(), endTime: new Date(), status: 'Finished.' }; cbStatus(err, finalStatus); deepExtend(processFullPipelineResult_1, finalStatus); cbFinal(err, processFullPipelineResult_1); }); }); }); }); } catch (err) { cbFinal(err); } }; VitaTasksImpl = VitaTasksImpl_1 = __decorate([ inversify_1.injectable(), __param(0, inversify_1.inject('CommandUtil')), __param(1, inversify_1.inject('VitaFileUtil')), __param(2, inversify_1.inject('ProgressBar')), __param(3, inversify_1.inject('VitaPcapMerge')), __param(4, inversify_1.inject('VitaDecryptUnTar')), __metadata("design:paramtypes", [Object, Object, Object, Object, Object]) ], VitaTasksImpl); return VitaTasksImpl; var VitaTasksImpl_1; }(firmament_yargs_1.ForceErrorImpl)); exports.VitaTasksImpl = VitaTasksImpl; //# sourceMappingURL=vita-tasks-impl.js.map