diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36f2e13..3f6b78dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,6 +37,7 @@ jobs: CX_CLIENT_ID: ${{ secrets.CLIENT_ID}} CX_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET}} CX_BASE_URI: ${{ secrets.BASE_URI }} + CX_TENANT: ${{ secrets.TENANT }} PATH_TO_EXECUTABLE: /tmp/cx-linux run: npm test \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f9dbcf25..0af9da01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@CheckmarxDev/ast-cli-javascript-wrapper", - "version": "0.0.23", + "version": "0.0.24", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4a465536..1b30cba2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@CheckmarxDev/ast-cli-javascript-wrapper", - "version": "0.0.24", + "version": "0.0.25", "description": "AST CLI Javascript wrapper", "main": "dist/CxAuth.js", "typings": "dist/CxAuth.d.ts", diff --git a/src/main/CxAuth.ts b/src/main/CxAuth.ts index d788e08f..b5c51e01 100644 --- a/src/main/CxAuth.ts +++ b/src/main/CxAuth.ts @@ -16,21 +16,22 @@ export class CxAuth { apiKey: string = ""; commands: string[] = []; pathToExecutable: string; + tenant: string; constructor(cxScanConfig: CxScanConfig) { let path = require("path"); - if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null && cxScanConfig.clientId !== '' && cxScanConfig.clientId !== '') { + if (cxScanConfig.clientId && cxScanConfig.clientSecret) { console.log("Received clientId and clientSecret"); this.clientId = cxScanConfig.clientId; this.clientSecret = cxScanConfig.clientSecret; - } else if (cxScanConfig.apiKey != null) { + } else if (cxScanConfig.apiKey) { this.apiKey = cxScanConfig.apiKey; } else { console.log("Did not receive ClientId/Secret or ApiKey from cli arguments"); } let executablePath: string; - if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") { + if (cxScanConfig.pathToExecutable) { this.pathToExecutable = cxScanConfig.pathToExecutable; } else if (process.platform === 'win32') { executablePath = path.join(__dirname, '/resources/cx.exe'); @@ -45,29 +46,37 @@ export class CxAuth { fs.chmodSync(this.pathToExecutable, 0o777); } - if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') { + if (cxScanConfig.baseUri) { this.baseUri = cxScanConfig.baseUri; } + + if (cxScanConfig.tenant) { + this.tenant = cxScanConfig.tenant; + } } initializeCommands(formatRequired: boolean): string[] { let list: string[] = []; - if (this.clientId !== null && this.clientId.length > 1) { + if (this.clientId) { list.push("--client-id"); list.push(this.clientId); } - if (this.clientSecret !== null && this.clientSecret.length > 1) { + if (this.clientSecret) { list.push("--client-secret"); list.push(this.clientSecret); } - if (this.apiKey !== null && this.apiKey.length > 1) { + if (this.apiKey) { list.push("--apikey"); list.push(this.apiKey); } - if (this.baseUri !== null && this.baseUri.length > 1) { + if (this.baseUri) { list.push("--base-uri"); list.push(this.baseUri); } + if (this.tenant) { + list.push("--tenant"); + list.push(this.tenant); + } if (formatRequired) { list.push("--format"); list.push("json"); @@ -81,16 +90,16 @@ export class CxAuth { this.commands.push("scan"); this.commands.push("create"); params.forEach((value: string, key: CxParamType) => { - if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value !== undefined && value.length > 1) { + if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value) { this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase()); this.commands.push(value); - } else if (key.length === 1 && value !== null && value !== undefined) { + } else if (key.length === 1 && value) { this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase()); this.commands.push(value); } else if (key === CxParamType.ADDITIONAL_PARAMETERS) { let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g); console.log("Additional parameters refined: " + paramList) - if (paramList !== null) { + if (paramList) { paramList.forEach((element) => { this.commands.push(element); }); @@ -132,13 +141,13 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("list"); - if (scanId !== null && scanId !== "") { + if (scanId) { this.commands.push("--scan-id") this.commands.push(scanId) } else { console.log("Scan Id not provided") } - if (formatType !== null && formatType != '') { + if (formatType) { this.commands.push("--format") this.commands.push(formatType) } @@ -150,17 +159,17 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("summary"); - if (scanId !== null && scanId !== "") { + if (scanId) { this.commands.push("--scan-id") this.commands.push(scanId) } else { console.log("Scan Id not provided") } - if (formatType !== null && formatType != '') { + if (formatType) { this.commands.push("--format") this.commands.push(formatType) } - if (target !== null && target != '') { + if (target) { this.commands.push("--target") this.commands.push(target) } @@ -172,7 +181,7 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push(resultParam); - if (targetPath !== null && targetPath !== "") { + if (targetPath) { this.commands.push("--target"); this.commands.push(targetPath); } diff --git a/src/main/CxScanConfig.ts b/src/main/CxScanConfig.ts index 33134c7b..48216071 100644 --- a/src/main/CxScanConfig.ts +++ b/src/main/CxScanConfig.ts @@ -4,4 +4,5 @@ export class CxScanConfig { clientId: string = " "; clientSecret: string = " "; apiKey: string = " "; + tenant:string =" "; } \ No newline at end of file diff --git a/src/tests/CxAuthCall.test.ts b/src/tests/CxAuthCall.test.ts index 2462b27c..9c33f4a1 100644 --- a/src/tests/CxAuthCall.test.ts +++ b/src/tests/CxAuthCall.test.ts @@ -9,6 +9,7 @@ let cxScanConfig = new CxScanConfig(); cxScanConfig.baseUri = process.env["CX_BASE_URI"]; cxScanConfig.clientId = process.env["CX_CLIENT_ID"]; cxScanConfig.clientSecret = process.env["CX_CLIENT_SECRET"]; +cxScanConfig.tenant = process.env["CX_TENANT"]; if(process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined ) { cxScanConfig.pathToExecutable = process.env["PATH_TO_EXECUTABLE"]; }