UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

110 lines (108 loc) 5.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const evaluateSecurityAudit_1 = require("./evaluateSecurityAudit"); const rest_1 = require("@gitbeaker/rest"); const createSecurityAuditMergeRequest_1 = require("./createSecurityAuditMergeRequest"); const ts_results_es_1 = require("ts-results-es"); const GITLAB_HOST = "https://git.panter.ch"; function default_1(vorpal) { commandCiJob(vorpal); commandEvaluate(vorpal); commandCreate(vorpal); } exports.default = default_1; function resultAsExitCode(func) { return async (args) => { const result = await func(args); process.exitCode = result.isErr() ? 1 : 0; }; } async function commandCiJob(vorpal) { vorpal .command("security-audit-ci-job <path> <token> <mainBranch> <projectId> <userId>", `Evaluates security audit document. If the document can't be evaluated or does not exist, creates a new MR with security audit document template. <path> root path of a project with security audit document (${createSecurityAuditMergeRequest_1.SECURITY_AUDIT_FILE_NAME}) <token> gitlab token with 'api' scopes and permissions to create a new branch <main-branch> main branch name <project-id> project id to create security audit for <user-id> gitlab user id that will be assignee of the audit `) .action(resultAsExitCode(async (args) => { const evaluation = await (0, evaluateSecurityAudit_1.evaluateSecurityAudit)({ path: args.path }); if (evaluation.isErr()) { console.log("could not evaluate security audit document"); console.log("creating new merge request with security audit template..."); const { token, mainBranch, projectId, userId } = args; const api = new rest_1.Gitlab({ host: GITLAB_HOST, token, }); const mr = await (0, createSecurityAuditMergeRequest_1.createSecurityAuditMergeRequest)({ api, mainBranch, projectId, userId: parseInt(userId), }); if (mr.isErr()) { console.error(`could not create merge request with security audit template: ${mr.error}`); return mr; } console.log("security audit merge request created successfully"); console.log(`please finish the MR by updating SECURITY.md document: ${mr.value.web_url}`); return (0, ts_results_es_1.Err)("merge request created"); } if (evaluation.value.score.answeredTopics === 0) { console.error("audit document has no answered topics"); console.error(`please answer security topics in ${createSecurityAuditMergeRequest_1.SECURITY_AUDIT_FILE_NAME} by adding responsible people and check/cross in the table`); return (0, ts_results_es_1.Err)("audit document has no answered topics"); } console.log((0, evaluateSecurityAudit_1.makeSecurityAuditOverview)(evaluation.value)); return (0, ts_results_es_1.Ok)({}); })); } async function commandEvaluate(vorpal) { vorpal .command("security-audit-evaluate <path>", "Evaluates security audit document in given <path>") .action(resultAsExitCode(async (args) => { console.log("evaluating security audit document..."); const result = await (0, evaluateSecurityAudit_1.evaluateSecurityAudit)({ path: args.path }); if (result.isErr()) { console.error(result.error); console.error(`please make sure the security audit document ${createSecurityAuditMergeRequest_1.SECURITY_AUDIT_FILE_NAME} is in the repository`); } else { console.log((0, evaluateSecurityAudit_1.makeSecurityAuditOverview)(result.value)); } return result; })); } async function commandCreate(vorpal) { vorpal .command("security-audit-create <token> <mainBranch> <projectId> <userId>", `Creates a MR in given project with the latest security audit template document <token> gitlab token with 'api' scopes and permissions to create a new branch <main-branch> main branch name <project-id> project id to create security audit for <user-id> gitlab user id that will be assignee of the audit `) .action(resultAsExitCode(async (args) => { const { token, mainBranch, projectId, userId } = args; const api = new rest_1.Gitlab({ host: GITLAB_HOST, token, }); const result = await (0, createSecurityAuditMergeRequest_1.createSecurityAuditMergeRequest)({ api, mainBranch, projectId, userId: parseInt(userId), }); if (result.isErr()) { console.error(`could not create security audit merge request: ${result.error}`); } else { console.log("security audit merge request created successfully"); console.log(`please finish the MR by updating SECURITY.md document: ${result.value.web_url}`); } return result; })); } //# sourceMappingURL=commands.js.map