diff --git a/src/main/scaRealtime/CxScaRealTime.ts b/src/main/scaRealtime/CxScaRealTime.ts new file mode 100644 index 00000000..1549bd29 --- /dev/null +++ b/src/main/scaRealtime/CxScaRealTime.ts @@ -0,0 +1,12 @@ +export default class CxScaRealTime { + totalCount: string; + results: any = []; + + static parseScaRealTimeResponse(resultObject: any): CxScaRealTime { + const scaRealTime: CxScaRealTime = new CxScaRealTime(); + scaRealTime.totalCount = resultObject.totalCount; + scaRealTime.results = resultObject.results || []; + + return scaRealTime; + } +} \ No newline at end of file diff --git a/src/main/wrapper/CxConstants.ts b/src/main/wrapper/CxConstants.ts index 933040ef..9c69a086 100644 --- a/src/main/wrapper/CxConstants.ts +++ b/src/main/wrapper/CxConstants.ts @@ -41,6 +41,8 @@ export enum CxConstants { SUB_CMD_BFL = "bfl", CMD_CODE_BASHING = "codebashing", CMD_KICS_REALTIME = "kics-realtime", + CMD_SCA_REALTIME = "sca-realtime", + CMD_SCA_REALTIME_PROJECT_DIR = "--project-dir", SCAN_INFO_FORMAT = "--scan-info-format", FORMAT = "--format", FORMAT_JSON = "json", @@ -67,6 +69,7 @@ export enum CxConstants { PREDICATE_TYPE = "CxPredicate", CODE_BASHING_TYPE = "CxCodeBashing", KICS_REALTIME_TYPE = "CxKicsRealTime", + SCA_REALTIME_TYPE = "CxScaRealTime", LEARN_MORE_DESCRIPTIONS_TYPE = "CxLearnMoreDescriptions", KICS_REMEDIATION_TYPE = "CxKicsRemediation", BFL_TYPE = "CxBFL", diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index 9b9e0633..7d94f3f8 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -252,6 +252,17 @@ export class CxWrapper { return exec.executeKicsCommands(this.config.pathToExecutable, commands, CxConstants.KICS_REALTIME_TYPE); } + /** + * Run SCA Realtime for a specific directory + * + * @param projectDirPath + */ + async runScaRealtimeScan(projectDirPath: string): Promise { + const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.CMD_SCA_REALTIME, CxConstants.CMD_SCA_REALTIME_PROJECT_DIR, projectDirPath]; + commands.push(...this.initializeCommands(false)); + return new ExecutionService().executeCommands(this.config.pathToExecutable, commands, CxConstants.SCA_REALTIME_TYPE); + } + async learnMore(queryId: string){ const commands: string[] = [CxConstants.CMD_UTILS,CxConstants.CMD_LEARN_MORE,CxConstants.QUERY_ID,queryId] diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index f03ba603..1da7ca9f 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -19,6 +19,7 @@ import CxCvss from "../results/CxCvss"; import CxNode from "../results/CxNode"; import CxPackageData from "../results/CxPackageData"; import CxKicsRemediation from "../remediation/CxKicsRemediation"; +import CxScaRealTime from "../scaRealtime/CxScaRealTime"; function isJsonString(s: string) { @@ -196,6 +197,10 @@ export class ExecutionService { const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject); cxCommandOutput.payload = [kicsResults]; break; + case CxConstants.SCA_REALTIME_TYPE: + const scaRealtimeResponse = CxScaRealTime.parseScaRealTimeResponse(resultObject); + cxCommandOutput.payload = [scaRealtimeResponse]; + break; case CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE: const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject); cxCommandOutput.payload = learnMore; diff --git a/src/tests/ScanTest.test.ts b/src/tests/ScanTest.test.ts index 01c5b5ab..028531cf 100644 --- a/src/tests/ScanTest.test.ts +++ b/src/tests/ScanTest.test.ts @@ -100,6 +100,17 @@ describe("ScanCreate cases", () => { expect(pid).toBeDefined(); }) + it('ScaRealtime Successful case', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.runScaRealtimeScan(process.cwd()); + if(cxCommandOutput.exitCode == 1) { + expect(cxCommandOutput.payload).toBeUndefined(); + } else { + const scanObject = cxCommandOutput.payload.pop(); + expect(scanObject.results).toBeDefined(); + } + }) + it("Should check if scan create is possible", async() => { const auth = new CxWrapper(cxScanConfig); const tenantSettings: boolean = await auth.ideScansEnabled();