UNPKG

@ylveracode/veracode-cli

Version:

a NodeJS based API wrapper for utilizing the Veracode APIs

61 lines (60 loc) 2.76 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 prompts_1 = __importDefault(require("prompts")); const workspaces_1 = require("../../apis/sca/workspaces"); exports.command = 'deleteWorkspaces [inputfile]'; exports.desc = 'delete a list of workspaces based on a list in a file. (can be generated by running the listWorkspaces)'; exports.builder = (yargs) => { return yargs .option('inputfile', { alias: 'input', describe: 'Input file name', 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 = {}; console.log('Found %d workspaces definition to delete', jsonInput.length); const nonZero = jsonInput.filter((ws) => { return ws.projects_count > 0; }); if (nonZero.length > 0) { console.log('Found %d non-empty workspaces definition to delete (according to the input file)', nonZero.length); } const deletingConfirmationResponse = yield prompts_1.default({ type: 'confirm', name: 'proceed', message: 'Proceed with the workspace deletion?', }); if (deletingConfirmationResponse.proceed) { for (let ws of jsonInput) { console.log('removing workspace %s, with site id: %s', ws.name, ws.id); const deleteRes = yield workspaces_1.deleteWorkspace(ws.guid); console.log(deleteRes); } } else { console.log('Gracefully exit.'); process.exit(0); } console.log('Done'); });