Skip to content

Commit b85223a

Browse files
authored
Add tenant to CxScanConfig properties (#13)
* add tenant to scanconfig
1 parent 82dfbd9 commit b85223a

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
CX_CLIENT_ID: ${{ secrets.CLIENT_ID}}
3838
CX_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET}}
3939
CX_BASE_URI: ${{ secrets.BASE_URI }}
40+
CX_TENANT: ${{ secrets.TENANT }}
4041
PATH_TO_EXECUTABLE: /tmp/cx-linux
4142
run: npm test
4243

package-lock.json

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
{
22
"name": "@CheckmarxDev/ast-cli-javascript-wrapper",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"description": "AST CLI Javascript wrapper",
55
"main": "dist/CxAuth.js",
66
"typings": "dist/CxAuth.d.ts",

src/main/CxAuth.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ export class CxAuth {
1616
apiKey: string = "";
1717
commands: string[] = [];
1818
pathToExecutable: string;
19+
tenant: string;
1920

2021
constructor(cxScanConfig: CxScanConfig) {
2122
let path = require("path");
22-
if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null && cxScanConfig.clientId !== '' && cxScanConfig.clientId !== '') {
23+
if (cxScanConfig.clientId && cxScanConfig.clientSecret) {
2324
console.log("Received clientId and clientSecret");
2425
this.clientId = cxScanConfig.clientId;
2526
this.clientSecret = cxScanConfig.clientSecret;
26-
} else if (cxScanConfig.apiKey != null) {
27+
} else if (cxScanConfig.apiKey) {
2728
this.apiKey = cxScanConfig.apiKey;
2829
} else {
2930
console.log("Did not receive ClientId/Secret or ApiKey from cli arguments");
3031
}
3132
let executablePath: string;
3233

33-
if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") {
34+
if (cxScanConfig.pathToExecutable) {
3435
this.pathToExecutable = cxScanConfig.pathToExecutable;
3536
} else if (process.platform === 'win32') {
3637
executablePath = path.join(__dirname, '/resources/cx.exe');
@@ -45,29 +46,37 @@ export class CxAuth {
4546
fs.chmodSync(this.pathToExecutable, 0o777);
4647
}
4748

48-
if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') {
49+
if (cxScanConfig.baseUri) {
4950
this.baseUri = cxScanConfig.baseUri;
5051
}
52+
53+
if (cxScanConfig.tenant) {
54+
this.tenant = cxScanConfig.tenant;
55+
}
5156
}
5257

5358
initializeCommands(formatRequired: boolean): string[] {
5459
let list: string[] = [];
55-
if (this.clientId !== null && this.clientId.length > 1) {
60+
if (this.clientId) {
5661
list.push("--client-id");
5762
list.push(this.clientId);
5863
}
59-
if (this.clientSecret !== null && this.clientSecret.length > 1) {
64+
if (this.clientSecret) {
6065
list.push("--client-secret");
6166
list.push(this.clientSecret);
6267
}
63-
if (this.apiKey !== null && this.apiKey.length > 1) {
68+
if (this.apiKey) {
6469
list.push("--apikey");
6570
list.push(this.apiKey);
6671
}
67-
if (this.baseUri !== null && this.baseUri.length > 1) {
72+
if (this.baseUri) {
6873
list.push("--base-uri");
6974
list.push(this.baseUri);
7075
}
76+
if (this.tenant) {
77+
list.push("--tenant");
78+
list.push(this.tenant);
79+
}
7180
if (formatRequired) {
7281
list.push("--format");
7382
list.push("json");
@@ -81,16 +90,16 @@ export class CxAuth {
8190
this.commands.push("scan");
8291
this.commands.push("create");
8392
params.forEach((value: string, key: CxParamType) => {
84-
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value !== undefined && value.length > 1) {
93+
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value) {
8594
this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
8695
this.commands.push(value);
87-
} else if (key.length === 1 && value !== null && value !== undefined) {
96+
} else if (key.length === 1 && value) {
8897
this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
8998
this.commands.push(value);
9099
} else if (key === CxParamType.ADDITIONAL_PARAMETERS) {
91100
let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g);
92101
console.log("Additional parameters refined: " + paramList)
93-
if (paramList !== null) {
102+
if (paramList) {
94103
paramList.forEach((element) => {
95104
this.commands.push(element);
96105
});
@@ -132,13 +141,13 @@ export class CxAuth {
132141
this.commands = this.initializeCommands(false);
133142
this.commands.push("result");
134143
this.commands.push("list");
135-
if (scanId !== null && scanId !== "") {
144+
if (scanId) {
136145
this.commands.push("--scan-id")
137146
this.commands.push(scanId)
138147
} else {
139148
console.log("Scan Id not provided")
140149
}
141-
if (formatType !== null && formatType != '') {
150+
if (formatType) {
142151
this.commands.push("--format")
143152
this.commands.push(formatType)
144153
}
@@ -150,17 +159,17 @@ export class CxAuth {
150159
this.commands = this.initializeCommands(false);
151160
this.commands.push("result");
152161
this.commands.push("summary");
153-
if (scanId !== null && scanId !== "") {
162+
if (scanId) {
154163
this.commands.push("--scan-id")
155164
this.commands.push(scanId)
156165
} else {
157166
console.log("Scan Id not provided")
158167
}
159-
if (formatType !== null && formatType != '') {
168+
if (formatType) {
160169
this.commands.push("--format")
161170
this.commands.push(formatType)
162171
}
163-
if (target !== null && target != '') {
172+
if (target) {
164173
this.commands.push("--target")
165174
this.commands.push(target)
166175
}
@@ -172,7 +181,7 @@ export class CxAuth {
172181
this.commands = this.initializeCommands(false);
173182
this.commands.push("result");
174183
this.commands.push(resultParam);
175-
if (targetPath !== null && targetPath !== "") {
184+
if (targetPath) {
176185
this.commands.push("--target");
177186
this.commands.push(targetPath);
178187
}

src/main/CxScanConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export class CxScanConfig {
44
clientId: string = " ";
55
clientSecret: string = " ";
66
apiKey: string = " ";
7+
tenant:string =" ";
78
}

src/tests/CxAuthCall.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let cxScanConfig = new CxScanConfig();
99
cxScanConfig.baseUri = process.env["CX_BASE_URI"];
1010
cxScanConfig.clientId = process.env["CX_CLIENT_ID"];
1111
cxScanConfig.clientSecret = process.env["CX_CLIENT_SECRET"];
12+
cxScanConfig.tenant = process.env["CX_TENANT"];
1213
if(process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined ) {
1314
cxScanConfig.pathToExecutable = process.env["PATH_TO_EXECUTABLE"];
1415
}

0 commit comments

Comments
 (0)