1
- import { CxConfig } from "./CxConfig" ;
2
- import { CxParamType } from "./CxParamType" ;
3
- import { CxConstants } from "./CxConstants" ;
4
- import { ExecutionService } from "./ExecutionService" ;
5
- import { CxCommandOutput } from "./CxCommandOutput" ;
6
- import { getLoggerWithFilePath , logger } from "./loggerConfig" ;
1
+ import { CxConfig } from "./CxConfig" ;
2
+ import { CxParamType } from "./CxParamType" ;
3
+ import { CxConstants } from "./CxConstants" ;
4
+ import { ExecutionService } from "./ExecutionService" ;
5
+ import { CxCommandOutput } from "./CxCommandOutput" ;
6
+ import { getLoggerWithFilePath , logger } from "./loggerConfig" ;
7
7
import * as fs from "fs"
8
8
import * as os from "os" ;
9
9
import CxBFL from "../bfl/CxBFL" ;
10
10
import path = require( 'path' ) ;
11
- import { getTrimmedMapValue } from "./utils" ;
11
+ import { getTrimmedMapValue } from "./utils" ;
12
12
13
13
type ParamTypeMap = Map < CxParamType , string > ;
14
14
@@ -57,7 +57,7 @@ export class CxWrapper {
57
57
}
58
58
}
59
59
60
-
60
+
61
61
initializeCommands ( formatRequired : boolean ) : string [ ] {
62
62
const list : string [ ] = [ ] ;
63
63
if ( this . config . clientId ) {
@@ -84,8 +84,8 @@ export class CxWrapper {
84
84
list . push ( CxConstants . TENANT ) ;
85
85
list . push ( this . config . tenant ) ;
86
86
}
87
- if ( this . config . additionalParameters ) {
88
- this . prepareAdditionalParams ( this . config . additionalParameters ) . forEach ( function ( param ) {
87
+ if ( this . config . additionalParameters ) {
88
+ this . prepareAdditionalParams ( this . config . additionalParameters ) . forEach ( function ( param ) {
89
89
list . push ( param )
90
90
} )
91
91
}
@@ -216,9 +216,9 @@ export class CxWrapper {
216
216
return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PREDICATE_TYPE ) ;
217
217
}
218
218
219
- async triageUpdate ( projectId : string , similarityId : string , scanType : string , state : string , comment : string , severity : string , stateId :number | null = null ) : Promise < CxCommandOutput > {
219
+ async triageUpdate ( projectId : string , similarityId : string , scanType : string , state : string , comment : string , severity : string , stateId : number | null = null ) : Promise < CxCommandOutput > {
220
220
const commands : string [ ] = [ CxConstants . CMD_TRIAGE , CxConstants . SUB_CMD_UPDATE , CxConstants . PROJECT_ID , projectId , CxConstants . SIMILARITY_ID , similarityId , CxConstants . SCAN_TYPES_SUB_CMD , scanType , CxConstants . STATE , state , CxConstants . COMMENT , comment , CxConstants . SEVERITY , severity ] ;
221
- if ( stateId ) {
221
+ if ( stateId ) {
222
222
commands . push ( CxConstants . STATE_ID )
223
223
commands . push ( stateId . toString ( ) )
224
224
}
@@ -245,7 +245,7 @@ export class CxWrapper {
245
245
return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . config . pathToExecutable , fileName ) ;
246
246
}
247
247
248
- async riskManagementResults ( projectId : string , scanId : string , limit ?: number ) : Promise < CxCommandOutput > {
248
+ async riskManagementResults ( projectId : string , scanId : string , limit ?: number ) : Promise < CxCommandOutput > {
249
249
const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . CMD_RISK_MANAGEMENT ] ;
250
250
commands . push ( CxConstants . PROJECT_ID , projectId ) ;
251
251
commands . push ( CxConstants . SCAN_ID , scanId ) ;
@@ -313,10 +313,10 @@ export class CxWrapper {
313
313
return response ;
314
314
}
315
315
316
- async kicsRealtimeScan ( fileSources : string , engine :string , additionalParams : string ) :Promise < [ Promise < CxCommandOutput > , any ] > {
316
+ async kicsRealtimeScan ( fileSources : string , engine : string , additionalParams : string ) : Promise < [ Promise < CxCommandOutput > , any ] > {
317
317
const commands : string [ ] = [ CxConstants . CMD_SCAN , CxConstants . CMD_KICS_REALTIME , CxConstants . FILE_SOURCES , fileSources , CxConstants . ADDITONAL_PARAMS , additionalParams ] ;
318
- if ( engine . length > 0 ) {
319
- commands . push ( CxConstants . ENGINE , engine )
318
+ if ( engine . length > 0 ) {
319
+ commands . push ( CxConstants . ENGINE , engine )
320
320
}
321
321
commands . push ( ...this . initializeCommands ( false ) ) ;
322
322
const exec = new ExecutionService ( ) ;
@@ -335,66 +335,66 @@ export class CxWrapper {
335
335
}
336
336
337
337
338
- async learnMore ( queryId : string ) {
339
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_LEARN_MORE , CxConstants . QUERY_ID , queryId ]
338
+ async learnMore ( queryId : string ) {
339
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_LEARN_MORE , CxConstants . QUERY_ID , queryId ]
340
340
commands . push ( ...this . initializeCommands ( true ) )
341
341
const exec = new ExecutionService ( ) ;
342
342
return exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . LEARN_MORE_DESCRIPTIONS_TYPE ) ;
343
343
}
344
344
345
- async kicsRemediation ( resultsFile : string , kicsFile :string , engine :string , similarityIds ?: string ) :Promise < [ Promise < CxCommandOutput > , any ] > {
346
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . KICS , CxConstants . KICS_REMEDIATION_RESULTS_FILE , resultsFile , CxConstants . KICS_REMEDIATION_KICS_FILE , kicsFile ] ;
347
- if ( engine . length > 0 ) {
348
- commands . push ( CxConstants . ENGINE , engine )
345
+ async kicsRemediation ( resultsFile : string , kicsFile : string , engine : string , similarityIds ?: string ) : Promise < [ Promise < CxCommandOutput > , any ] > {
346
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . KICS , CxConstants . KICS_REMEDIATION_RESULTS_FILE , resultsFile , CxConstants . KICS_REMEDIATION_KICS_FILE , kicsFile ] ;
347
+ if ( engine . length > 0 ) {
348
+ commands . push ( CxConstants . ENGINE , engine )
349
349
}
350
- if ( similarityIds ) {
351
- commands . push ( CxConstants . KICS_REMEDIATION_SIMILARITY_IDS , similarityIds )
350
+ if ( similarityIds ) {
351
+ commands . push ( CxConstants . KICS_REMEDIATION_SIMILARITY_IDS , similarityIds )
352
352
}
353
353
commands . push ( ...this . initializeCommands ( false ) ) ;
354
354
const exec = new ExecutionService ( ) ;
355
355
return exec . executeKicsCommands ( this . config . pathToExecutable , commands , CxConstants . KICS_REMEDIATION_TYPE ) ;
356
356
}
357
357
358
- async scaRemediation ( packageFiles : string , packages :string , packageVersion :string ) : Promise < CxCommandOutput > {
359
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . SUB_CMD_REMEDIATION_SCA , CxConstants . SCA_REMEDIATION_PACKAGE_FILES , packageFiles , CxConstants . SCA_REMEDIATION_PACKAGE , packages , CxConstants . SCA_REMEDIATION_PACKAGE_VERSION , packageVersion ] ;
358
+ async scaRemediation ( packageFiles : string , packages : string , packageVersion : string ) : Promise < CxCommandOutput > {
359
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . CMD_REMEDIATION , CxConstants . SUB_CMD_REMEDIATION_SCA , CxConstants . SCA_REMEDIATION_PACKAGE_FILES , packageFiles , CxConstants . SCA_REMEDIATION_PACKAGE , packages , CxConstants . SCA_REMEDIATION_PACKAGE_VERSION , packageVersion ] ;
360
360
commands . push ( ...this . initializeCommands ( false ) ) ;
361
361
const exec = new ExecutionService ( ) ;
362
362
return exec . executeCommands ( this . config . pathToExecutable , commands ) ;
363
363
}
364
364
365
365
async ideScansEnabled ( ) : Promise < boolean > {
366
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
367
- commands . push ( ...this . initializeCommands ( false ) ) ;
366
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
367
+ commands . push ( ...this . initializeCommands ( false ) ) ;
368
368
369
- const exec = new ExecutionService ( ) ;
370
- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
369
+ const exec = new ExecutionService ( ) ;
370
+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
371
371
372
- const value = getTrimmedMapValue ( output , CxConstants . IDE_SCANS_KEY ) ;
373
- return value ?. toLowerCase ( ) === "true" ;
374
- }
372
+ const value = getTrimmedMapValue ( output , CxConstants . IDE_SCANS_KEY ) ;
373
+ return value ?. toLowerCase ( ) === "true" ;
374
+ }
375
375
376
376
async guidedRemediationEnabled ( ) : Promise < boolean > {
377
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
378
- commands . push ( ...this . initializeCommands ( false ) ) ;
377
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
378
+ commands . push ( ...this . initializeCommands ( false ) ) ;
379
379
380
- const exec = new ExecutionService ( ) ;
381
- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
380
+ const exec = new ExecutionService ( ) ;
381
+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
382
382
383
- const value = getTrimmedMapValue ( output , CxConstants . AI_GUIDED_REMEDIATION_KEY ) ;
384
- return value ?. toLowerCase ( ) === "true" ;
385
- }
383
+ const value = getTrimmedMapValue ( output , CxConstants . AI_GUIDED_REMEDIATION_KEY ) ;
384
+ return value ?. toLowerCase ( ) === "true" ;
385
+ }
386
386
387
387
388
- async aiMcpServerEnabled ( ) : Promise < boolean > {
389
- const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
390
- commands . push ( ...this . initializeCommands ( false ) ) ;
388
+ async aiMcpServerEnabled ( ) : Promise < boolean > {
389
+ const commands : string [ ] = [ CxConstants . CMD_UTILS , CxConstants . SUB_CMD_TENANT ] ;
390
+ commands . push ( ...this . initializeCommands ( false ) ) ;
391
391
392
- const exec = new ExecutionService ( ) ;
393
- const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
392
+ const exec = new ExecutionService ( ) ;
393
+ const output = await exec . executeMapTenantOutputCommands ( this . config . pathToExecutable , commands ) ;
394
394
395
- const value = getTrimmedMapValue ( output , CxConstants . AI_MCP_SERVER_KEY ) ;
396
- return value ?. toLowerCase ( ) === "true" ;
397
- }
395
+ const value = getTrimmedMapValue ( output , CxConstants . AI_MCP_SERVER_KEY ) ;
396
+ return value ?. toLowerCase ( ) === "true" ;
397
+ }
398
398
399
399
async kicsChat ( apikey : string , file : string , line : number , severity : string , vulnerability : string , input : string , conversationId ?: string , model ?: string ) : Promise < CxCommandOutput > {
400
400
const commands : string [ ] = [
@@ -437,7 +437,7 @@ export class CxWrapper {
437
437
return new ExecutionService ( ) . executeCommands ( this . config . pathToExecutable , commands , CxConstants . CHAT_TYPE ) ;
438
438
}
439
439
440
- async maskSecrets ( file : string ) : Promise < CxCommandOutput > {
440
+ async maskSecrets ( file : string ) : Promise < CxCommandOutput > {
441
441
const commands : string [ ] = [
442
442
CxConstants . CMD_UTILS ,
443
443
CxConstants . CMD_MASK_SECRETS ,
@@ -448,10 +448,26 @@ export class CxWrapper {
448
448
return new ExecutionService ( ) . executeCommands ( this . config . pathToExecutable , commands , CxConstants . MASK_TYPE ) ;
449
449
}
450
450
451
- prepareAdditionalParams ( additionalParameters : string ) : string [ ] {
451
+ telemetryAIEvent ( aiProvider : string , agent : string , timestamp : Date , clickType : string , engine : string , problemSeverity : string ) : Promise < CxCommandOutput > {
452
+ const commands : string [ ] = [
453
+ CxConstants . TELEMETRY ,
454
+ CxConstants . SUB_CMD_TELEMETRY_AI ,
455
+ CxConstants . AI_PROVIDER , aiProvider ,
456
+ CxConstants . AGENT , agent ,
457
+ CxConstants . TIMESTAMP , timestamp . toISOString ( ) ,
458
+ CxConstants . CLICK_TYPE , clickType ,
459
+ CxConstants . ENGINE , engine ,
460
+ CxConstants . PROBLEM_SEVERITY , problemSeverity
461
+ ] ;
462
+ commands . push ( ...this . initializeCommands ( true ) ) ;
463
+ const exec = new ExecutionService ( ) ;
464
+ return exec . executeCommands ( this . config . pathToExecutable , commands ) ;
465
+ }
466
+
467
+ prepareAdditionalParams ( additionalParameters : string ) : string [ ] {
452
468
const params : string [ ] = [ ] ;
453
469
454
- if ( ! additionalParameters ) {
470
+ if ( ! additionalParameters ) {
455
471
return params ;
456
472
}
457
473
0 commit comments