|
| 1 | +const core = require('@actions/core'); |
| 2 | +const exec = require('@actions/exec'); |
| 3 | +const common = require('actions-common-scans'); |
| 4 | +const _ = require('lodash'); |
| 5 | + |
| 6 | +// Default file names |
| 7 | +let jsonReportName = 'report_json.json'; |
| 8 | +let mdReportName = 'report_md.md'; |
| 9 | +let htmlReportName = 'report_html.html'; |
| 10 | + |
| 11 | +async function run() { |
| 12 | + |
| 13 | + try { |
| 14 | + let workspace = process.env.GITHUB_WORKSPACE; |
| 15 | + let currentRunnerID = process.env.GITHUB_RUN_ID; |
| 16 | + let repoName = process.env.GITHUB_REPOSITORY; |
| 17 | + let token = core.getInput('token'); |
| 18 | + let docker_name = core.getInput('docker_name'); |
| 19 | + let target = core.getInput('target'); |
| 20 | + let rulesFileLocation = core.getInput('rules_file_name'); |
| 21 | + let cmdOptions = core.getInput('cmd_options'); |
| 22 | + let issueTitle = core.getInput('issue_title'); |
| 23 | + |
| 24 | + console.log('starting the program'); |
| 25 | + console.log('github run id :' + currentRunnerID); |
| 26 | + |
| 27 | + let plugins = []; |
| 28 | + if (rulesFileLocation) { |
| 29 | + plugins = await common.helper.processLineByLine(`${workspace}/${rulesFileLocation}`); |
| 30 | + } |
| 31 | + |
| 32 | + let command = (`docker run --user root -v ${workspace}:/zap/wrk/:rw --network="host" ` + |
| 33 | + `-t ${docker_name} zap-full-scan.py -t ${target} -J ${jsonReportName} -w ${mdReportName} -r ${htmlReportName} ${cmdOptions}`); |
| 34 | + |
| 35 | + if (plugins.length !== 0) { |
| 36 | + command = command + ` -c ${rulesFileLocation}` |
| 37 | + } |
| 38 | + |
| 39 | + try { |
| 40 | + await exec.exec(command); |
| 41 | + } catch (err) { |
| 42 | + core.setFailed('The ZAP Baseline scan has failed, starting to analyze the alerts. err: ' + err.toString()); |
| 43 | + } |
| 44 | + await common.main.processReport(token, workspace, plugins, currentRunnerID, issueTitle, repoName); |
| 45 | + } catch (error) { |
| 46 | + core.setFailed(error.message); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +run(); |
0 commit comments