Skip to content

Commit bd7a2b6

Browse files
Merge pull request #373 from CheckmarxDev/feature-handle-sca-realtime
Feature handle sca realtime
2 parents 1f8a705 + dcd2f97 commit bd7a2b6

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default class CxScaRealTime {
2+
totalCount: string;
3+
results: any = [];
4+
5+
static parseScaRealTimeResponse(resultObject: any): CxScaRealTime {
6+
const scaRealTime: CxScaRealTime = new CxScaRealTime();
7+
scaRealTime.totalCount = resultObject.totalCount;
8+
scaRealTime.results = resultObject.results || [];
9+
10+
return scaRealTime;
11+
}
12+
}

src/main/wrapper/CxConstants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export enum CxConstants {
4141
SUB_CMD_BFL = "bfl",
4242
CMD_CODE_BASHING = "codebashing",
4343
CMD_KICS_REALTIME = "kics-realtime",
44+
CMD_SCA_REALTIME = "sca-realtime",
45+
CMD_SCA_REALTIME_PROJECT_DIR = "--project-dir",
4446
SCAN_INFO_FORMAT = "--scan-info-format",
4547
FORMAT = "--format",
4648
FORMAT_JSON = "json",
@@ -67,6 +69,7 @@ export enum CxConstants {
6769
PREDICATE_TYPE = "CxPredicate",
6870
CODE_BASHING_TYPE = "CxCodeBashing",
6971
KICS_REALTIME_TYPE = "CxKicsRealTime",
72+
SCA_REALTIME_TYPE = "CxScaRealTime",
7073
LEARN_MORE_DESCRIPTIONS_TYPE = "CxLearnMoreDescriptions",
7174
KICS_REMEDIATION_TYPE = "CxKicsRemediation",
7275
BFL_TYPE = "CxBFL",

src/main/wrapper/CxWrapper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ export class CxWrapper {
252252
return exec.executeKicsCommands(this.config.pathToExecutable, commands, CxConstants.KICS_REALTIME_TYPE);
253253
}
254254

255+
/**
256+
* Run SCA Realtime for a specific directory
257+
*
258+
* @param projectDirPath
259+
*/
260+
async runScaRealtimeScan(projectDirPath: string): Promise<CxCommandOutput> {
261+
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.CMD_SCA_REALTIME, CxConstants.CMD_SCA_REALTIME_PROJECT_DIR, projectDirPath];
262+
commands.push(...this.initializeCommands(false));
263+
return new ExecutionService().executeCommands(this.config.pathToExecutable, commands, CxConstants.SCA_REALTIME_TYPE);
264+
}
265+
255266

256267
async learnMore(queryId: string){
257268
const commands: string[] = [CxConstants.CMD_UTILS,CxConstants.CMD_LEARN_MORE,CxConstants.QUERY_ID,queryId]

src/main/wrapper/ExecutionService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import CxCvss from "../results/CxCvss";
1919
import CxNode from "../results/CxNode";
2020
import CxPackageData from "../results/CxPackageData";
2121
import CxKicsRemediation from "../remediation/CxKicsRemediation";
22+
import CxScaRealTime from "../scaRealtime/CxScaRealTime";
2223

2324

2425
function isJsonString(s: string) {
@@ -196,6 +197,10 @@ export class ExecutionService {
196197
const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject);
197198
cxCommandOutput.payload = [kicsResults];
198199
break;
200+
case CxConstants.SCA_REALTIME_TYPE:
201+
const scaRealtimeResponse = CxScaRealTime.parseScaRealTimeResponse(resultObject);
202+
cxCommandOutput.payload = [scaRealtimeResponse];
203+
break;
199204
case CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE:
200205
const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject);
201206
cxCommandOutput.payload = learnMore;

src/tests/ScanTest.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ describe("ScanCreate cases", () => {
100100
expect(pid).toBeDefined();
101101
})
102102

103+
it('ScaRealtime Successful case', async () => {
104+
const wrapper = new CxWrapper(cxScanConfig);
105+
const cxCommandOutput: CxCommandOutput = await wrapper.runScaRealtimeScan(process.cwd());
106+
if(cxCommandOutput.exitCode == 1) {
107+
expect(cxCommandOutput.payload).toBeUndefined();
108+
} else {
109+
const scanObject = cxCommandOutput.payload.pop();
110+
expect(scanObject.results).toBeDefined();
111+
}
112+
})
113+
103114
it("Should check if scan create is possible", async() => {
104115
const auth = new CxWrapper(cxScanConfig);
105116
const tenantSettings: boolean = await auth.ideScansEnabled();

0 commit comments

Comments
 (0)