@ylveracode/veracode-cli
Version:
a NodeJS based API wrapper for utilizing the Veracode APIs
71 lines (70 loc) • 3.1 kB
JavaScript
;
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 workspaces_1 = require("../../apis/sca/workspaces");
const fs_1 = __importDefault(require("fs"));
exports.command = 'listWorkspaces [options]';
exports.desc = 'create a file with JSON content with Workspaces with their name, ID and, GUID';
exports.builder = (yargs) => {
return yargs
.option('filename', {
alias: 'f',
describe: 'The output file name',
default: 'workspaces.json'
})
.option('verbose', {
describe: "Output result to screen"
});
};
exports.handler = function (argv) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
console.log('Outputing workspaces to %s', argv.filename);
let notDone = true;
let page = 0;
let overallResults = [];
while (notDone) {
console.log('Querying page: %i', page);
const workspaces = yield workspaces_1.getWorkspaces(page);
let workspacesArr = (_a = workspaces === null || workspaces === void 0 ? void 0 : workspaces._embedded) === null || _a === void 0 ? void 0 : _a.workspaces;
if (workspacesArr) {
let parsed = workspacesArr.map((ws) => {
return {
name: ws.name,
guid: ws.id,
id: ws.site_id,
projects_count: parseInt(ws.projects_count)
};
});
//console.log(parsed);
overallResults = overallResults.concat(parsed);
}
if (workspaces.page.number + 1 < workspaces.page.total_pages) {
page++;
}
else {
notDone = false;
}
}
//console.log(overallResults);
console.log('Printing to file "%s"', argv.filename);
fs_1.default.writeFileSync(argv.filename, JSON.stringify(overallResults, null, 4), { encoding: 'utf-8' });
if (argv.verbose) {
overallResults.forEach((ws) => {
console.log('Workspace: [%s], site: [%s] has [%d] projects', ws.name, ws.id, ws.projects_count);
});
}
console.log('Done');
});
};