Skip to content

Commit 09475c2

Browse files
authored
Feature/change exit code strategy (#3)
* Changed exit strategy
1 parent b4aa13f commit 09475c2

19 files changed

+2173
-908
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ jobs:
3939
CX_BASE_URI: ${{ secrets.BASE_URI }}
4040
PATH_TO_EXECUTABLE: /tmp/cx-linux
4141
run: npm test
42+
- name: 'Upload Artifact'
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: cxAST.log
46+
path: cxAST.log
47+
retention-days: 30
48+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/
2+
dist/tests/

package-lock.json

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

package.json

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
11
{
22
"name": "@CheckmarxDev/ast-cli-javascript-wrapper",
3-
"version": "1.0.3",
3+
"version": "0.0.15",
44
"description": "AST CLI Javascript wrapper",
5-
"main": "dist/CxAuthCall.js",
6-
"typings": "dist/CxAuthCall.d.ts",
5+
"main": "dist/CxAuth.js",
6+
"typings": "dist/CxAuth.d.ts",
77
"jest": {
88
"verbose": true
99
},
1010
"type": "commonjs",
1111
"files": [
12-
"src/*",
13-
"out/*",
12+
"dist/main/resources/cx*",
13+
"dist/main/*.ts",
14+
"dist/main/*.js",
15+
"dist/main/*.map",
1416
"babel.config.js",
1517
"jest.config.js",
1618
"jest.setup.js",
1719
"README.md"
1820
],
1921
"dependencies": {
20-
"@babel/plugin-proposal-class-properties": "^7.13.0",
21-
"@babel/preset-env": "^7.14.2",
22-
"@babel/preset-react": "^7.13.13",
23-
"@babel/preset-typescript": "^7.13.0",
24-
"babel-core": "^6.26.3",
25-
"babel-jest": "^27.0.1",
26-
"babel-polyfill": "^6.26.0",
22+
"typescript-logging": "^1.0.0",
2723
"log4js": "6.3.0",
28-
"ts-node": "^9.1.1",
29-
"typescript": "^4.3.2",
30-
"typescript-logging": "^1.0.0"
24+
"tslog": "3.2.0"
3125
},
3226
"scripts": {
3327
"build": "tsc",
34-
"test": "jest"
28+
"postbuild": "copyfiles -u 1 src/main/resources/cx* dist/",
29+
"test": "jest -i --silent=false"
3530
},
3631
"repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git",
3732
"author": "Jay Nanduri",
@@ -41,9 +36,19 @@
4136
},
4237
"homepage": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper#readme",
4338
"devDependencies": {
39+
"@babel/plugin-proposal-class-properties": "^7.13.0",
40+
"@babel/preset-env": "^7.14.2",
41+
"@babel/preset-react": "^7.13.13",
42+
"@babel/preset-typescript": "^7.13.0",
4443
"@types/jest": "^26.0.23",
4544
"@types/node": "^15.6.1",
46-
"jest": "^27.0.1",
45+
"@types/regenerator-runtime": "^0.13.0",
46+
"babel-core": "^6.26.3",
47+
"babel-jest": "^27.0.1",
48+
"babel-plugin-transform-regenerator": "^6.26.0",
49+
"babel-polyfill": "^6.26.0",
50+
"copyfiles": "^2.4.1",
51+
"jest": "^27.0.6",
4752
"ts-jest": "^26.5.6"
4853
},
4954
"publishConfig": {

src/CxAuth.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/CxScanConfig.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/main/ConfigLog4j.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
import 'regenerator-runtime/runtime'
2-
import {CxScanConfigCall} from "./CxScanConfigCall";
2+
import {CxScanConfig} from "./CxScanConfig";
33
import {CxParamType} from "./CxParamType";
44
import {ExecutionService} from "./ExecutionService";
55
import {spawn} from "child_process";
66
import {CxResultType} from "./CxResultType";
7+
import {CxCommandOutput} from "./CxCommandOutput";
78

89
type ParamTypeMap = Map<CxParamType, string>;
910

10-
export class CxAuthCall {
11+
export class CxAuth {
1112
baseUri: string = "";
1213
clientId: string = "";
1314
clientSecret: string = "";
1415
apiKey: string = "";
1516
commands: string[] = [];
1617
pathToExecutable: string;
1718

18-
constructor(cxScanConfig: CxScanConfigCall) {
19+
constructor(cxScanConfig: CxScanConfig) {
1920
let path = require("path");
20-
if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null) {
21+
if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null && cxScanConfig.clientId !== '' && cxScanConfig.clientId !== '') {
2122
console.log("Received clientId and clientSecret");
2223
this.clientId = cxScanConfig.clientId;
2324
this.clientSecret = cxScanConfig.clientSecret;
2425
} else if (cxScanConfig.apiKey != null) {
2526
this.apiKey = cxScanConfig.apiKey;
2627
} else {
27-
console.log("Did not receive ClientId/Secret or ApiKey");
28+
console.log("Did not receive ClientId/Secret or ApiKey from cli arguments");
2829
}
2930
let executablePath: string;
31+
32+
3033
if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") {
3134
this.pathToExecutable = cxScanConfig.pathToExecutable;
3235
} else if (process.platform === 'win32') {
@@ -40,26 +43,26 @@ export class CxAuthCall {
4043
executablePath = path.join(__dirname, '/resources/cx-linux');
4144
this.pathToExecutable = executablePath;
4245
}
43-
if (cxScanConfig.baseUri !== null) {
46+
if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') {
4447
this.baseUri = cxScanConfig.baseUri;
4548
}
4649
}
4750

4851
initializeCommands(formatRequired: boolean): string[] {
4952
let list: string[] = [];
50-
if (this.clientId !== null && this.clientId !== "") {
53+
if (this.clientId !== null && this.clientId.length > 1) {
5154
list.push("--client-id");
5255
list.push(this.clientId);
5356
}
54-
if (this.clientSecret !== null && this.clientSecret !== "") {
57+
if (this.clientSecret !== null && this.clientSecret.length > 1) {
5558
list.push("--client-secret");
5659
list.push(this.clientSecret);
5760
}
58-
if (this.apiKey !== null && this.apiKey !== "") {
61+
if (this.apiKey !== null && this.apiKey.length > 1) {
5962
list.push("--apikey");
6063
list.push(this.apiKey);
6164
}
62-
if (this.baseUri !== null && this.baseUri !== "") {
65+
if (this.baseUri !== null && this.baseUri.length > 1) {
6366
list.push("--base-uri");
6467
list.push(this.baseUri);
6568
}
@@ -71,18 +74,18 @@ export class CxAuthCall {
7174
return list;
7275
}
7376

74-
async scanCreate(params: ParamTypeMap): Promise<string> {
77+
async scanCreate(params: ParamTypeMap): Promise<CxCommandOutput> {
7578
this.commands = this.initializeCommands(true);
7679
this.commands.push("scan");
7780
this.commands.push("create");
7881
params.forEach((value: string, key: CxParamType) => {
79-
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1) {
82+
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value!== undefined && value.length > 1) {
8083
this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
8184
this.commands.push(value);
82-
} else if (key.length === 1) {
85+
} else if (key.length === 1 && value !== null && value!== undefined) {
8386
this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
8487
this.commands.push(value);
85-
} else {
88+
} else if(key === CxParamType.ADDITIONAL_PARAMETERS) {
8689
let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g);
8790
console.log("Additional parameters refined: " + paramList)
8891
if (paramList !== null) {
@@ -97,24 +100,25 @@ export class CxAuthCall {
97100
return await exec.executeCommands(this.pathToExecutable, this.commands);
98101
}
99102

100-
async scanShow(id: string): Promise<string> {
103+
async scanShow(id: string): Promise<CxCommandOutput> {
101104
this.commands = this.initializeCommands(true);
102105
this.commands.push("scan");
103106
this.commands.push("show");
107+
this.commands.push("--scan-id");
104108
this.commands.push(id);
105109
let exec = new ExecutionService();
106110
return await exec.executeCommands(this.pathToExecutable, this.commands);
107111
}
108112

109-
async scanList(): Promise<string> {
113+
async scanList(): Promise<CxCommandOutput> {
110114
this.commands = this.initializeCommands(true);
111115
this.commands.push("scan");
112116
this.commands.push("list");
113117
let exec = new ExecutionService();
114118
return await exec.executeCommands(this.pathToExecutable, this.commands);
115119
}
116120

117-
async projectList(): Promise<string> {
121+
async projectList(): Promise<CxCommandOutput> {
118122
this.commands = this.initializeCommands(true);
119123
this.commands.push("project");
120124
this.commands.push("list");

src/main/CxCommandOutput.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import CxScan from "./CxScan";
2+
3+
export class CxCommandOutput {
4+
exitCode: number = 0;
5+
scanObjectList: CxScan[];
6+
}

0 commit comments

Comments
 (0)