UNPKG

@ylveracode/veracode-cli

Version:

a NodeJS based API wrapper for utilizing the Veracode APIs

97 lines (96 loc) 4.02 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const buildInfo_1 = require("../../apis/sast/buildInfo"); exports.command = 'identifyOpenPolicyScan [inputfile] [options]'; exports.desc = 'create a list of workspaces which can be deleted - with zero project, and at least one more workspace with the same name'; exports.builder = (yargs) => { return yargs .option('inputfile', { alias: 'input', describe: 'Input file name - which contain a reqponce from list application request', default: 'apps.json', nargs: 1, demandOption: false, type: "string" }) .option('since', { describe: "number of hours from which a scan request was opened since", default: 0, nargs: 1, demandOption: false, type: "number" }) .strictOptions(true) .help(); }; exports.handler = (argv) => __awaiter(void 0, void 0, void 0, function* () { try { fs_1.default.accessSync(argv.inputfile, fs_1.default.constants.R_OK); } catch (err) { console.log(`Input file [${argv.inputfile}] does not exist`); return; } const input = fs_1.default.readFileSync(argv.inputfile, { encoding: 'utf-8' }); let jsonInput; try { jsonInput = JSON.parse(input); } catch (err) { console.log('Error parsing the file content. Maybe not in JSON format'); return; } // to keep referance to a workspaces we want to keep with instead of no duplicate of a workspace with zero let apps = []; if (jsonInput._embedded) { apps = jsonInput._embedded.applications; } else { apps = [jsonInput]; } const foundProfiles = apps.filter((app) => { var _a; const staticScans = (_a = app.scans) === null || _a === void 0 ? void 0 : _a.filter((scan) => scan.scan_type === 'STATIC'); if (staticScans.length === 0 || staticScans[0].status === 'PUBLISHED') { return false; } return true; }); const suspects = yield Promise.all(foundProfiles.map((app) => __awaiter(void 0, void 0, void 0, function* () { const build = yield buildInfo_1.getBuildInfo(app.id); return { appId: app.id, name: app.profile.name, guid: app.guid, policyBuild: build['$'] }; }))); const oldPolicyScansProfiles = suspects.filter(app => { if (app.policyBuild.policy_updated_date) { const maybe = new Date(app.policyBuild.policy_updated_date); //console.log(maybe.toLocaleString()); const diff = Date.now() - maybe; const hours = Math.floor(diff / 1000 / 60 / 60); const minutes = Math.floor((diff - (hours * 3600000)) / 60000); console.log(`${diff} millis which equates to ${Math.floor(diff / 1000 / 60 / 60)} hours and ${minutes} minutes for app: ${app.name}`); return (hours > argv.since); } else { return true; } }); console.log(JSON.stringify(oldPolicyScansProfiles, undefined, ' ')); });