Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
35910d3
Added typescript files
May 20, 2021
49af610
Added jest test cases and babel configuration
May 27, 2021
7a82348
added the test file
May 27, 2021
4668a36
Update wrapperTester.ts
jay-nanduri May 27, 2021
20e7184
added configuration to generate type declarations
May 27, 2021
1d5a9cf
deleted custom types defines earlier
May 27, 2021
8da802d
Added project list function
May 27, 2021
ed8346f
changes to generate mock results
May 27, 2021
e8ac53f
added jest configuration and mock results
May 28, 2021
0539c2e
Github action to perform Integration testing
May 28, 2021
bbc5ddd
package lock added
May 28, 2021
dfc64b3
Reformat code and added env variables
May 28, 2021
2a70cbd
added path configuration to getResults function
May 28, 2021
9c40e1e
changed main.yml config
May 28, 2021
fdbff2c
changed main.yml config
May 31, 2021
fc2c304
changed main.yml config
May 31, 2021
55b4cc1
changed main.yml config
May 31, 2021
62d5aea
changed main.yml config
May 31, 2021
e4b68e4
changed the param
May 31, 2021
95dbeba
changed the param
May 31, 2021
be73c91
changed the param
May 31, 2021
9a4eaab
changed the param
May 31, 2021
05e9053
changed the param
May 31, 2021
39173b6
removed toString
May 31, 2021
056334d
Added tests step
May 31, 2021
c91aa38
modified test cases
May 31, 2021
3c2eeba
Added publish step
May 31, 2021
37b7e64
Added publish step
May 31, 2021
1af2732
Added npmrc file
May 31, 2021
53c7064
added npm auth step
May 31, 2021
2201002
added npm auth step
May 31, 2021
9fdd016
publish package
May 31, 2021
75d6549
publish package
May 31, 2021
404faec
converted the javascript wrapper to typescript and added automation
May 31, 2021
6ef52cc
removed the comments
Jun 1, 2021
1f87861
included dist in package
Jun 4, 2021
e98c105
included dist in package
Jun 4, 2021
83d909a
changed package version
Jun 4, 2021
6424e16
changed package version
Jun 4, 2021
e80e937
changed package version
Jun 14, 2021
63910b8
changed package version
Jul 6, 2021
597c9a8
changed package version
Jul 9, 2021
a9fe46b
Cleaned up code and added the exit code feature
Jul 21, 2021
761d4e3
Changed the file names and added test cases
Jul 21, 2021
e6f0273
Changed CLI version and integration test cases
Jul 21, 2021
41e506b
changed Test cases
Jul 21, 2021
8fb688e
corrected test cases and increased version
Jul 21, 2021
514edc3
Merge branch 'feature/add-exit-code' into feature/change-exit-code-st…
Jul 21, 2021
f23e4b7
changes to remove redundant files
Jul 21, 2021
5463096
changed integration test cases
Jul 22, 2021
8d67c9c
added logs and changed the tests
Jul 22, 2021
2d9ef87
Added log artifact step to main.yml
Jul 22, 2021
40246b7
removed reject from Execution Service
Jul 22, 2021
8d0954d
changed the log from error to info
Jul 22, 2021
80bb868
removed unnecessary file and changed jest version
Jul 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ jobs:
CX_BASE_URI: ${{ secrets.BASE_URI }}
PATH_TO_EXECUTABLE: /tmp/cx-linux
run: npm test
- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
with:
name: cxAST.log
path: cxAST.log
retention-days: 30

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/
dist/tests/
2,700 changes: 2,006 additions & 694 deletions package-lock.json

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
{
"name": "@CheckmarxDev/ast-cli-javascript-wrapper",
"version": "1.0.3",
"version": "0.0.15",
"description": "AST CLI Javascript wrapper",
"main": "dist/CxAuthCall.js",
"typings": "dist/CxAuthCall.d.ts",
"main": "dist/CxAuth.js",
"typings": "dist/CxAuth.d.ts",
"jest": {
"verbose": true
},
"type": "commonjs",
"files": [
"src/*",
"out/*",
"dist/main/resources/cx*",
"dist/main/*.ts",
"dist/main/*.js",
"dist/main/*.map",
"babel.config.js",
"jest.config.js",
"jest.setup.js",
"README.md"
],
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.14.2",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"babel-core": "^6.26.3",
"babel-jest": "^27.0.1",
"babel-polyfill": "^6.26.0",
"typescript-logging": "^1.0.0",
"log4js": "6.3.0",
"ts-node": "^9.1.1",
"typescript": "^4.3.2",
"typescript-logging": "^1.0.0"
"tslog": "3.2.0"
},
"scripts": {
"build": "tsc",
"test": "jest"
"postbuild": "copyfiles -u 1 src/main/resources/cx* dist/",
"test": "jest -i --silent=false"
},
"repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git",
"author": "Jay Nanduri",
Expand All @@ -41,9 +36,19 @@
},
"homepage": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper#readme",
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.14.2",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^26.0.23",
"@types/node": "^15.6.1",
"jest": "^27.0.1",
"@types/regenerator-runtime": "^0.13.0",
"babel-core": "^6.26.3",
"babel-jest": "^27.0.1",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-polyfill": "^6.26.0",
"copyfiles": "^2.4.1",
"jest": "^27.0.6",
"ts-jest": "^26.5.6"
},
"publishConfig": {
Expand Down
76 changes: 0 additions & 76 deletions src/CxAuth.js

This file was deleted.

61 changes: 0 additions & 61 deletions src/CxScanConfig.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/ConfigLog4j.ts

This file was deleted.

38 changes: 21 additions & 17 deletions src/main/CxAuthCall.ts → src/main/CxAuth.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
import 'regenerator-runtime/runtime'
import {CxScanConfigCall} from "./CxScanConfigCall";
import {CxScanConfig} from "./CxScanConfig";
import {CxParamType} from "./CxParamType";
import {ExecutionService} from "./ExecutionService";
import {spawn} from "child_process";
import {CxResultType} from "./CxResultType";
import {CxCommandOutput} from "./CxCommandOutput";

type ParamTypeMap = Map<CxParamType, string>;

export class CxAuthCall {
export class CxAuth {
baseUri: string = "";
clientId: string = "";
clientSecret: string = "";
apiKey: string = "";
commands: string[] = [];
pathToExecutable: string;

constructor(cxScanConfig: CxScanConfigCall) {
constructor(cxScanConfig: CxScanConfig) {
let path = require("path");
if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null) {
if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null && cxScanConfig.clientId !== '' && cxScanConfig.clientId !== '') {
console.log("Received clientId and clientSecret");
this.clientId = cxScanConfig.clientId;
this.clientSecret = cxScanConfig.clientSecret;
} else if (cxScanConfig.apiKey != null) {
this.apiKey = cxScanConfig.apiKey;
} else {
console.log("Did not receive ClientId/Secret or ApiKey");
console.log("Did not receive ClientId/Secret or ApiKey from cli arguments");
}
let executablePath: string;


if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") {
this.pathToExecutable = cxScanConfig.pathToExecutable;
} else if (process.platform === 'win32') {
Expand All @@ -40,26 +43,26 @@ export class CxAuthCall {
executablePath = path.join(__dirname, '/resources/cx-linux');
this.pathToExecutable = executablePath;
}
if (cxScanConfig.baseUri !== null) {
if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') {
this.baseUri = cxScanConfig.baseUri;
}
}

initializeCommands(formatRequired: boolean): string[] {
let list: string[] = [];
if (this.clientId !== null && this.clientId !== "") {
if (this.clientId !== null && this.clientId.length > 1) {
list.push("--client-id");
list.push(this.clientId);
}
if (this.clientSecret !== null && this.clientSecret !== "") {
if (this.clientSecret !== null && this.clientSecret.length > 1) {
list.push("--client-secret");
list.push(this.clientSecret);
}
if (this.apiKey !== null && this.apiKey !== "") {
if (this.apiKey !== null && this.apiKey.length > 1) {
list.push("--apikey");
list.push(this.apiKey);
}
if (this.baseUri !== null && this.baseUri !== "") {
if (this.baseUri !== null && this.baseUri.length > 1) {
list.push("--base-uri");
list.push(this.baseUri);
}
Expand All @@ -71,18 +74,18 @@ export class CxAuthCall {
return list;
}

async scanCreate(params: ParamTypeMap): Promise<string> {
async scanCreate(params: ParamTypeMap): Promise<CxCommandOutput> {
this.commands = this.initializeCommands(true);
this.commands.push("scan");
this.commands.push("create");
params.forEach((value: string, key: CxParamType) => {
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1) {
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value!== undefined && value.length > 1) {
this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
this.commands.push(value);
} else if (key.length === 1) {
} else if (key.length === 1 && value !== null && value!== undefined) {
this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
this.commands.push(value);
} else {
} else if(key === CxParamType.ADDITIONAL_PARAMETERS) {
let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g);
console.log("Additional parameters refined: " + paramList)
if (paramList !== null) {
Expand All @@ -97,24 +100,25 @@ export class CxAuthCall {
return await exec.executeCommands(this.pathToExecutable, this.commands);
}

async scanShow(id: string): Promise<string> {
async scanShow(id: string): Promise<CxCommandOutput> {
this.commands = this.initializeCommands(true);
this.commands.push("scan");
this.commands.push("show");
this.commands.push("--scan-id");
this.commands.push(id);
let exec = new ExecutionService();
return await exec.executeCommands(this.pathToExecutable, this.commands);
}

async scanList(): Promise<string> {
async scanList(): Promise<CxCommandOutput> {
this.commands = this.initializeCommands(true);
this.commands.push("scan");
this.commands.push("list");
let exec = new ExecutionService();
return await exec.executeCommands(this.pathToExecutable, this.commands);
}

async projectList(): Promise<string> {
async projectList(): Promise<CxCommandOutput> {
this.commands = this.initializeCommands(true);
this.commands.push("project");
this.commands.push("list");
Expand Down
6 changes: 6 additions & 0 deletions src/main/CxCommandOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import CxScan from "./CxScan";

export class CxCommandOutput {
exitCode: number = 0;
scanObjectList: CxScan[];
}
2 changes: 1 addition & 1 deletion src/main/CxParamType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum CxParamType {
S = "S", V = "V", G = "G", PROJECT_NAME = "PROJECT_NAME", SCAN_TYPES = "SCAN_TYPES", SAST_PRESET_NAME = "SAST_PRESET_NAME", FILTER = "FILTER", DIRECTORY = "DIRECTORY", ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS", AGENT = "AGENT", SOURCES = "SOURCES", TENANT = "TENANT"
S = "S", V = "V", G = "G", PROJECT_NAME = "PROJECT_NAME", SCAN_TYPES = "SCAN_TYPES", SAST_PRESET_NAME = "SAST_PRESET_NAME", FILTER = "FILTER", DIRECTORY = "DIRECTORY", ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS", AGENT = "AGENT", SOURCES = "SOURCES", TENANT = "TENANT", BRANCH = "BRANCH"
}
2 changes: 1 addition & 1 deletion src/main/CxResultType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum CxResultType {
LIST = "list", LIST_SIMPLE = "list-simple"
LIST = "list", SUMMARY = "summary"
}
2 changes: 1 addition & 1 deletion src/main/CxScanConfigCall.ts → src/main/CxScanConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class CxScanConfigCall {
export class CxScanConfig {
baseUri: string = "";
pathToExecutable: string = "";
clientId: string = " ";
Expand Down
Loading