Skip to content

Commit

Permalink
Add tenant to CxScanConfig properties (#13)
Browse files Browse the repository at this point in the history
* add tenant to scanconfig
  • Loading branch information
jay-nanduri authored Aug 31, 2021
1 parent 82dfbd9 commit b85223a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 26 additions & 17 deletions src/main/CxAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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");
Expand All @@ -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);
});
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/CxScanConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export class CxScanConfig {
clientId: string = " ";
clientSecret: string = " ";
apiKey: string = " ";
tenant:string =" ";
}
1 change: 1 addition & 0 deletions src/tests/CxAuthCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
}
Expand Down

0 comments on commit b85223a

Please sign in to comment.