UNPKG

@ylveracode/veracode-cli

Version:

a NodeJS based API wrapper for utilizing the Veracode APIs

71 lines (70 loc) 3.12 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")); exports.command = 'identifyRedundantWorkspaces [inputfile] [outputfile]'; 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. Can be created by running the list_workspaces command', default: 'workspaces.json' }) .option('outputfile', { alias: 'output', describe: "Output result to screen", default: 'emptyWorkspaces.json' }) .option('verbose', { describe: "Output result to screen" }); }; exports.handler = (argv) => __awaiter(void 0, void 0, void 0, function* () { const input = fs_1.default.readFileSync(argv.inputfile, { encoding: 'utf-8' }); const jsonInput = JSON.parse(input); // to keep referance to a workspaces we want to keep with instead of no duplicate of a workspace with zero const allZero = {}; const forReduction = jsonInput.filter((ws) => { if (ws.projects_count !== 0) { return false; } if (allZero[ws.name]) { return true; } // current WS got zero (0) projects const sameWithNoEmpty = jsonInput.filter((inner) => { return (inner.name === ws.name && (inner.projects_count > 0)); }); if (sameWithNoEmpty.length === 0) { // no other with same name, or, all other with same name has zero allZero[ws.name] = ws.id; return false; } else { // there are other workspaces with at least one project return true; } }); //console.log(overallResults); console.log('Printing to file "%s"', argv.outputfile); fs_1.default.writeFileSync(argv.outputfile, JSON.stringify(forReduction, null, 4), { encoding: 'utf-8' }); if (argv.verbose) { console.log('verbose'); forReduction.map((ws) => { console.log('Workspace: [%s], site: [%s] has [%d] projects', ws.name, ws.id, ws.projects_count); }); } console.log('Done'); });