@ylveracode/veracode-cli
Version:
a NodeJS based API wrapper for utilizing the Veracode APIs
53 lines (46 loc) • 1.82 kB
text/typescript
import fs from 'fs';
import {outputWS} from '../sca';
import prompts from 'prompts';
import {deleteWorkspace} from '../../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:any) => {
return yargs
.option('inputfile', {
alias: 'input',
describe: 'Input file name',
default: 'emptyWorkspaces.json'
})
// .option('verbose', {
// describe: "Output result to screen"
// });
}
exports.handler = async (argv:any) => {
const input = fs.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:any = {};
console.log('Found %d workspaces definition to delete',jsonInput.length);
const nonZero = jsonInput.filter((ws:outputWS) => {
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 = await prompts({
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 = await deleteWorkspace(ws.guid);
console.log(deleteRes);
}
} else {
console.log('Gracefully exit.');
process.exit(0);
}
console.log('Done');
}