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 { 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" ;
77import * as fs from "fs"
88import * as os from "os" ;
99import CxBFL from "../bfl/CxBFL" ;
@@ -13,9 +13,12 @@ type ParamTypeMap = Map<CxParamType, string>;
1313export class CxWrapper {
1414 config : CxConfig = new CxConfig ( ) ;
1515
16- constructor ( cxScanConfig : CxConfig ) {
16+ constructor ( cxScanConfig : CxConfig , logFilePath ?: string ) {
1717 let path = require ( "path" ) ;
18- if ( cxScanConfig . clientId && cxScanConfig . clientSecret ) {
18+
19+ getLoggerWithFilePath ( logFilePath )
20+
21+ if ( cxScanConfig . clientId && cxScanConfig . clientSecret ) {
1922 logger . info ( "Received clientId and clientSecret" ) ;
2023 this . config . clientId = cxScanConfig . clientId ;
2124 this . config . clientSecret = cxScanConfig . clientSecret ;
@@ -117,22 +120,29 @@ export class CxWrapper {
117120 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
118121 }
119122
123+ async scanCancel ( id : string ) : Promise < CxCommandOutput > {
124+ const commands : string [ ] = [ CxConstants . CMD_SCAN , CxConstants . SUB_CMD_CANCEL , CxConstants . SCAN_ID , id ] ;
125+ commands . push ( ...this . initializeCommands ( false ) ) ;
126+ const exec = new ExecutionService ( ) ;
127+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
128+ }
129+
120130 async scanShow ( id : string ) : Promise < CxCommandOutput > {
121131 const commands : string [ ] = [ CxConstants . CMD_SCAN , CxConstants . SUB_CMD_SHOW , CxConstants . SCAN_ID , id ] ;
122132 commands . push ( ...this . initializeCommands ( true ) ) ;
123133 const exec = new ExecutionService ( ) ;
124134 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
125135 }
126136
127- async scanList ( filters :string ) : Promise < CxCommandOutput > {
137+ async scanList ( filters : string ) : Promise < CxCommandOutput > {
128138 const validated_filters = this . filterArguments ( filters ) ;
129139 const commands : string [ ] = [ CxConstants . CMD_SCAN , "list" ] . concat ( validated_filters ) ;
130140 commands . push ( ...this . initializeCommands ( true ) ) ;
131141 const exec = new ExecutionService ( ) ;
132142 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
133143 }
134144
135- async projectList ( filters :string ) : Promise < CxCommandOutput > {
145+ async projectList ( filters : string ) : Promise < CxCommandOutput > {
136146 const validated_filters = this . filterArguments ( filters ) ;
137147 const commands : string [ ] = [ CxConstants . CMD_PROJECT , "list" ] . concat ( validated_filters ) ;
138148 commands . push ( ...this . initializeCommands ( true ) ) ;
@@ -143,32 +153,32 @@ export class CxWrapper {
143153 async projectBranches ( projectId : string , filters : string ) : Promise < CxCommandOutput > {
144154 // Verify and add possible branch filter by name
145155 const validated_filters = this . filterArguments ( CxConstants . BRANCH_NAME + filters )
146- const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_BRANCHES , CxConstants . PROJECT_ID , projectId ] . concat ( validated_filters ) ;
156+ const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_BRANCHES , CxConstants . PROJECT_ID , projectId ] . concat ( validated_filters ) ;
147157 commands . push ( ...this . initializeCommands ( false ) ) ;
148158 const exec = new ExecutionService ( ) ;
149159 return await exec . executeCommands ( this . config . pathToExecutable , commands ) ;
150160 }
151161
152162 async projectShow ( projectId : string ) : Promise < CxCommandOutput > {
153- const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_SHOW , CxConstants . PROJECT_ID , projectId ] ;
163+ const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_SHOW , CxConstants . PROJECT_ID , projectId ] ;
154164 commands . push ( ...this . initializeCommands ( true ) ) ;
155165 const exec = new ExecutionService ( ) ;
156166 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
157167 }
158168
159- async triageShow ( projectId : string , similarityId : string , scanType : string ) : Promise < CxCommandOutput > {
169+ async triageShow ( projectId : string , similarityId : string , scanType : string ) : Promise < CxCommandOutput > {
160170 const commands : string [ ] = [ CxConstants . CMD_TRIAGE , CxConstants . SUB_CMD_SHOW , CxConstants . PROJECT_ID , projectId , CxConstants . SIMILARITY_ID , similarityId , CxConstants . SCAN_TYPES_SUB_CMD , scanType ] ;
161171 commands . push ( ...this . initializeCommands ( true ) ) ;
162172 const exec = new ExecutionService ( ) ;
163173 return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PREDICATE_TYPE ) ;
164- }
165-
174+ }
175+
166176 async triageUpdate ( projectId : string , similarityId : string , scanType : string , state : string , comment : string , severity : string ) : Promise < CxCommandOutput > {
167177 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 ] ;
168178 commands . push ( ...this . initializeCommands ( false ) ) ;
169179 const exec = new ExecutionService ( ) ;
170180 return await exec . executeCommands ( this . config . pathToExecutable , commands ) ;
171- }
181+ }
172182
173183 async getResultsList ( scanId : string ) {
174184 const exec = new ExecutionService ( ) ;
@@ -177,7 +187,7 @@ export class CxWrapper {
177187 // Executes the command and creates a result file
178188 await exec . executeResultsCommands ( this . config . pathToExecutable , commands )
179189 // Reads the result file and retrieves the results
180- return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . config . pathToExecutable , fileName ) ;
190+ return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . config . pathToExecutable , fileName ) ;
181191 }
182192
183193 async getResultsSummary ( scanId : string ) : Promise < CxCommandOutput > {
@@ -187,24 +197,24 @@ export class CxWrapper {
187197 // Executes the command and creates a result file
188198 await exec . executeResultsCommands ( this . config . pathToExecutable , commands ) ;
189199 // Reads the result file and retrieves the results
190- return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_HTML , CxConstants . FORMAT_HTML_FILE , commands , this . config . pathToExecutable , fileName ) ;
200+ return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_HTML , CxConstants . FORMAT_HTML_FILE , commands , this . config . pathToExecutable , fileName ) ;
191201 }
192202
193- async getResults ( scanId : string , resultType :string , outputFileName : string , outputFilePath : string ) {
203+ async getResults ( scanId : string , resultType : string , outputFileName : string , outputFilePath : string ) {
194204 const commands = this . resultsShow ( scanId , resultType , outputFileName , outputFilePath )
195205 const exec = new ExecutionService ( ) ;
196206 return await exec . executeCommands ( this . config . pathToExecutable , commands ) ;
197207 }
198208
199- async codeBashingList ( cweId :string , language :string , queryName :string ) : Promise < CxCommandOutput > {
200- const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . CMD_CODE_BASHING , CxConstants . LANGUAGE , language , CxConstants . VULNERABILITY_TYPE , queryName , CxConstants . CWE_ID , cweId ] ;
209+ async codeBashingList ( cweId : string , language : string , queryName : string ) : Promise < CxCommandOutput > {
210+ const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . CMD_CODE_BASHING , CxConstants . LANGUAGE , language , CxConstants . VULNERABILITY_TYPE , queryName , CxConstants . CWE_ID , cweId ] ;
201211 commands . push ( ...this . initializeCommands ( true ) ) ;
202212 const exec = new ExecutionService ( ) ;
203- return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . CODE_BASHING_TYPE ) ;
213+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . CODE_BASHING_TYPE ) ;
204214 }
205215
206216 resultsShow ( scanId : string , reportFormat : string , outputFileName : string , outputPath : string ) : string [ ] {
207- const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . SUB_CMD_SHOW , CxConstants . SCAN_ID , scanId , CxConstants . REPORT_FORMAT , reportFormat ] ;
217+ const commands : string [ ] = [ CxConstants . CMD_RESULT , CxConstants . SUB_CMD_SHOW , CxConstants . SCAN_ID , scanId , CxConstants . REPORT_FORMAT , reportFormat ] ;
208218 if ( outputFileName ) {
209219 commands . push ( CxConstants . OUTPUT_NAME ) ;
210220 commands . push ( outputFileName ) ;
@@ -233,8 +243,7 @@ export class CxWrapper {
233243 for ( const bflNode of bflNodes ) {
234244 for ( const resultNode of resultNodes ) {
235245
236- if ( this . compareNodes ( bflNode , resultNode ) )
237- {
246+ if ( this . compareNodes ( bflNode , resultNode ) ) {
238247 return resultNodes . indexOf ( resultNode ) ;
239248 }
240249 }
@@ -244,22 +253,22 @@ export class CxWrapper {
244253
245254 }
246255
247- compareNodes ( bflNode : CxBFL , resultNode : any ) : boolean {
256+ compareNodes ( bflNode : CxBFL , resultNode : any ) : boolean {
248257
249258 return bflNode . line == resultNode . line &&
250- bflNode . column == resultNode . column &&
251- bflNode . length == resultNode . length &&
252- bflNode . name == resultNode . name &&
253- bflNode . method == resultNode . method &&
254- bflNode . domType == resultNode . domType &&
255- bflNode . fileName == resultNode . fileName &&
256- bflNode . fullName == resultNode . fullName &&
257- bflNode . methodLine == resultNode . methodLine ;
259+ bflNode . column == resultNode . column &&
260+ bflNode . length == resultNode . length &&
261+ bflNode . name == resultNode . name &&
262+ bflNode . method == resultNode . method &&
263+ bflNode . domType == resultNode . domType &&
264+ bflNode . fileName == resultNode . fileName &&
265+ bflNode . fullName == resultNode . fullName &&
266+ bflNode . methodLine == resultNode . methodLine ;
258267 }
259268
260- filterArguments ( filters :string ) :string [ ] {
269+ filterArguments ( filters : string ) : string [ ] {
261270 let r = [ ] ;
262- if ( filters . length > 0 ) {
271+ if ( filters . length > 0 ) {
263272 r . push ( CxConstants . FILTER ) ;
264273 r . push ( filters ) ;
265274 }
0 commit comments