Skip to content

Commit 6809b08

Browse files
committed
SCAN-5649 : Use version 2.0.0 of local scanner.
1 parent d3f3dc3 commit 6809b08

File tree

10 files changed

+924
-1925
lines changed

10 files changed

+924
-1925
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
node_modules
2+
target
3+
log
4+
results.sarif
5+
scan-summary.json
6+
.contrast-scan/
27
.vscode

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
FROM alpine:3.21.3
22

33
RUN apk upgrade && \
4-
apk add nodejs npm openjdk11-jre-headless tar zstd
4+
apk add nodejs npm openjdk21-jre-headless tar zstd
55

66
COPY package.json /contrast-local-scanner/package.json
77
RUN cd /contrast-local-scanner && npm i --production
88

9-
ENV ACTIONS_CACHE_SERVICE_V2 true
9+
ENV ACTIONS_CACHE_SERVICE_V2=true
1010

1111
COPY src /contrast-local-scanner/src
1212

package-lock.json

Lines changed: 836 additions & 1919 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"eslint-plugin-import": "^2.28.1",
2020
"eslint-plugin-prettier": "^5.1.3",
2121
"prettier": "^3.1.1",
22-
"release-it": "^18.1.2"
22+
"release-it": "^19.0.3"
2323
},
2424
"scripts": {
2525
"lint": "eslint src",

scripts/github-event.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ref": "refs/local/test",
3+
"repository": {
4+
"default_branch": "test"
5+
}
6+
}

scripts/run-container-locally.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# INPUT_${var} where var corresponds to those defined in action.yml uppercased
4+
#
5+
# Other env vars are those normally passed in by the github actions runner
6+
# as defined here https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
7+
8+
file=.
9+
project=contrast-local-scan-action-test
10+
11+
while getopts "f:p:" opt; do
12+
case $opt in
13+
f) file="$OPTARG" ;;
14+
p) project="$OPTARG" ;;
15+
esac
16+
done
17+
18+
docker run \
19+
-e INPUT_APIURL=$CONTRAST__API__URL \
20+
-e INPUT_APIUSERNAME=$CONTRAST__API__USER_NAME \
21+
-e INPUT_APIKEY=$CONTRAST__API__API_KEY \
22+
-e INPUT_APISERVICEKEY=$CONTRAST__API__SERVICE_KEY \
23+
-e INPUT_APIORGID=$CONTRAST__API__ORGANIZATION \
24+
-e INPUT_DEFAULTBRANCH=false \
25+
-e INPUT_CHECKS=false \
26+
-e INPUT_CODEQUALITY=false \
27+
-e INPUT_LABEL="local-test" \
28+
-e INPUT_TOKEN=unknown \
29+
-e INPUT_PROJECTNAME=$project \
30+
-e INPUT_RESOURCEGROUP=scan \
31+
-e ACTIONS_RUNTIME_TOKEN=unknown \
32+
-e RUNNER_TEMP=/tmp \
33+
-e GITHUB_JOB="local-test" \
34+
-e GITHUB_REF="refs/local/test" \
35+
-e GITHUB_SHA=c9f043b \
36+
-e GITHUB_EVENT_NAME="push" \
37+
-e GITHUB_REPOSITORY=contrast-local-scan-action-test \
38+
-e GITHUB_REPOSITORY_OWNER=Contrast-Security-OSS \
39+
-e GITHUB_REPOSITORY_OWNER_ID=1 \
40+
-e GITHUB_RUN_ID=1 \
41+
-e GITHUB_RUN_NUMBER=1 \
42+
-e GITHUB_WORKSPACE=/workspace \
43+
-e GITHUB_EVENT_PATH=/github/github-event.json \
44+
-w /workspace \
45+
-v ./target:/root/contrast-local-scanner/ \
46+
-v ./scripts/github-event.json:/github/github-event.json \
47+
-v $file:/workspace \
48+
$(docker build -q .)
49+

src/checks.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ async function startCheck() {
3636
}
3737

3838
function getOutputModel(details) {
39+
40+
if (!details) {
41+
return {
42+
conclusion: "action_required",
43+
report: "Local scan completed with error, please see logs for details"
44+
};
45+
}
46+
3947
return {
4048
conclusion: details.thresholdResults > 0 ? "action_required" : "success",
4149
report: buildReport(details),

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const ref = getRef();
8989
const label = core.getInput("label") || ref;
9090

9191
// Pinning the local scanner version
92-
const localScannerVersion = "1.1.8";
92+
const localScannerVersion = "2.0.0";
9393

9494
const memory = core.getInput("memory");
9595
const path = core.getInput("path") || process.env.GITHUB_WORKSPACE;

src/local-scanner.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const { localScannerVersion } = require("./config");
99
const CONTRAST_LOCAL_SCANNER = "contrast-local-scanner";
1010
const LOCAL_SCANNER_PATH = `${process.env.HOME}/${CONTRAST_LOCAL_SCANNER}`;
1111
const LOCAL_SCANNER_CACHE_KEY = `${CONTRAST_LOCAL_SCANNER}-${localScannerVersion}`;
12+
const JAR_NAME = `sast-local-scan-runner-${localScannerVersion}.jar`;
13+
const JAR_FULL_PATH = path.join(LOCAL_SCANNER_PATH, JAR_NAME);
1214

1315
async function getLocalScannerArtifact(version) {
1416
const artifacts = await getArtifacts(version);
@@ -48,7 +50,13 @@ async function saveCache() {
4850
}
4951

5052
async function getLocalScannerPath() {
51-
core.info(`Checking if ${CONTRAST_LOCAL_SCANNER} previously cached.`);
53+
54+
if (fs.existsSync(JAR_FULL_PATH)) {
55+
core.info(`${CONTRAST_LOCAL_SCANNER} exists locally`);
56+
return JAR_FULL_PATH;
57+
}
58+
59+
core.info(`${JAR_FULL_PATH} not found locally, checking if exists in cache.`);
5260

5361
const cacheKey = await restoreCache();
5462

src/request.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const core = require("@actions/core");
33

44
const { apiApiKey, apiAuthHeader, apiBaseUrl } = require("./config");
55

6-
const httpClient = new httpm.HttpClient();
6+
const httpClient = new httpm.HttpClient(
7+
'contrast-local-scan-action', // Sets user-agent
8+
[],
9+
{
10+
allowRedirects: false
11+
}
12+
);
713

814
async function request(path) {
915
const response = await httpClient.getJson(`${apiBaseUrl}/${path}`, {

0 commit comments

Comments
 (0)