1- import { CxScanConfig } from "../scan/CxScanConfig " ;
1+ import { CxConfig } from "./CxConfig " ;
22import { CxParamType } from "./CxParamType" ;
33import { CxConstants } from "./CxConstants" ;
44import { ExecutionService } from "./ExecutionService" ;
@@ -10,68 +10,63 @@ import * as os from "os";
1010type ParamTypeMap = Map < CxParamType , string > ;
1111
1212export class CxWrapper {
13- baseUri : string = "" ;
14- clientId : string = "" ;
15- clientSecret : string = "" ;
16- apiKey : string = "" ;
17- pathToExecutable : string ;
18- tenant : string ;
19-
20- constructor ( cxScanConfig : CxScanConfig ) {
13+ config : CxConfig = new CxConfig ( ) ;
14+
15+ constructor ( cxScanConfig : CxConfig ) {
2116 let path = require ( "path" ) ;
2217 if ( cxScanConfig . clientId && cxScanConfig . clientSecret ) {
2318 logger . info ( "Received clientId and clientSecret" ) ;
24- this . clientId = cxScanConfig . clientId ;
25- this . clientSecret = cxScanConfig . clientSecret ;
19+ this . config . clientId = cxScanConfig . clientId ;
20+ this . config . clientSecret = cxScanConfig . clientSecret ;
2621 } else if ( cxScanConfig . apiKey ) {
27- this . apiKey = cxScanConfig . apiKey ;
22+ this . config . apiKey = cxScanConfig . apiKey ;
2823 } else {
2924 logger . info ( "Did not receive ClientId/Secret or ApiKey from cli arguments" ) ;
3025 }
3126 let executablePath : string ;
3227 if ( cxScanConfig . pathToExecutable ) {
33- this . pathToExecutable = cxScanConfig . pathToExecutable ;
28+ this . config . pathToExecutable = cxScanConfig . pathToExecutable ;
3429 } else if ( process . platform === 'win32' ) {
3530 executablePath = path . join ( __dirname , '/resources/cx.exe' ) ;
36- this . pathToExecutable = executablePath ;
31+ this . config . pathToExecutable = executablePath ;
3732 } else if ( process . platform === 'darwin' ) {
3833 executablePath = path . join ( __dirname , '/resources/cx-mac' ) ;
39- this . pathToExecutable = executablePath ;
40- fs . chmodSync ( this . pathToExecutable , 0o777 ) ;
34+ this . config . pathToExecutable = executablePath ;
35+ fs . chmodSync ( this . config . pathToExecutable , 0o777 ) ;
4136 } else {
4237 executablePath = path . join ( __dirname , '/resources/cx-linux' ) ;
43- this . pathToExecutable = executablePath ;
44- fs . chmodSync ( this . pathToExecutable , 0o777 ) ;
38+ this . config . pathToExecutable = executablePath ;
39+ fs . chmodSync ( this . config . pathToExecutable , 0o777 ) ;
4540 }
4641 if ( cxScanConfig . baseUri ) {
47- this . baseUri = cxScanConfig . baseUri ;
42+ this . config . baseUri = cxScanConfig . baseUri ;
4843 }
4944 if ( cxScanConfig . tenant ) {
50- this . tenant = cxScanConfig . tenant ;
45+ this . config . tenant = cxScanConfig . tenant ;
5146 }
5247 }
5348
5449 initializeCommands ( formatRequired : boolean ) : string [ ] {
5550 const list : string [ ] = [ ] ;
56- if ( this . clientId ) {
51+ if ( this . config . clientId ) {
5752 list . push ( CxConstants . CLIENT_ID ) ;
58- list . push ( this . clientId ) ;
53+ list . push ( this . config . clientId ) ;
5954 }
60- if ( this . clientSecret ) {
55+ if ( this . config . clientSecret ) {
6156 list . push ( CxConstants . CLIENT_SECRET ) ;
62- list . push ( this . clientSecret ) ;
57+ list . push ( this . config . clientSecret ) ;
6358 }
64- if ( this . apiKey ) {
59+ if ( this . config . apiKey ) {
6560 list . push ( CxConstants . API_KEY ) ;
66- list . push ( this . apiKey ) ;
61+ list . push ( this . config . apiKey ) ;
6762 }
68- if ( this . baseUri ) {
63+ if ( this . config . baseUri ) {
6964 list . push ( CxConstants . BASE_URI ) ;
70- list . push ( this . baseUri ) ;
65+ list . push ( this . config . baseUri ) ;
7166 }
72- if ( this . tenant ) {
67+ if ( this . config . tenant ) {
7368 list . push ( CxConstants . TENANT ) ;
74- list . push ( this . tenant ) ;
69+ list . push ( this . config . tenant ) ;
7570 }
7671 if ( formatRequired ) {
7772 list . push ( CxConstants . FORMAT ) ;
@@ -101,37 +96,37 @@ export class CxWrapper {
10196 }
10297 } ) ;
10398 const exec = new ExecutionService ( ) ;
104- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
99+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
105100 }
106101
107102 async authValidate ( ) : Promise < CxCommandOutput > {
108103 const commands : string [ ] = [ CxConstants . CMD_AUTH , CxConstants . SUB_CMD_VALIDATE ] ;
109104 commands . push ( ...this . initializeCommands ( false ) ) ;
110105 let exec = new ExecutionService ( ) ;
111- return await exec . executeCommands ( this . pathToExecutable , commands ) ;
106+ return await exec . executeCommands ( this . config . pathToExecutable , commands ) ;
112107 }
113108
114109 async scanShow ( id : string ) : Promise < CxCommandOutput > {
115110 const commands : string [ ] = [ CxConstants . CMD_SCAN , CxConstants . SUB_CMD_SHOW , CxConstants . SCAN_ID , id ] ;
116111 commands . push ( ...this . initializeCommands ( true ) ) ;
117112 const exec = new ExecutionService ( ) ;
118- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
113+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
119114 }
120115
121116 async scanList ( filters :string ) : Promise < CxCommandOutput > {
122117 const validated_filters = this . filterArguments ( filters ) ;
123118 const commands : string [ ] = [ CxConstants . CMD_SCAN , "list" ] . concat ( validated_filters ) ;
124119 commands . push ( ...this . initializeCommands ( true ) ) ;
125120 const exec = new ExecutionService ( ) ;
126- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
121+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . SCAN_TYPE ) ;
127122 }
128123
129124 async projectList ( filters :string ) : Promise < CxCommandOutput > {
130125 const validated_filters = this . filterArguments ( filters ) ;
131126 const commands : string [ ] = [ CxConstants . CMD_PROJECT , "list" ] . concat ( validated_filters ) ;
132127 commands . push ( ...this . initializeCommands ( true ) ) ;
133128 const exec = new ExecutionService ( ) ;
134- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
129+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
135130 }
136131
137132 async projectBranches ( projectId : string , filters : string ) : Promise < CxCommandOutput > {
@@ -140,40 +135,40 @@ export class CxWrapper {
140135 const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_BRANCHES , CxConstants . PROJECT_ID , projectId ] . concat ( validated_filters ) ;
141136 commands . push ( ...this . initializeCommands ( false ) ) ;
142137 const exec = new ExecutionService ( ) ;
143- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
138+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
144139 }
145140
146141 async projectShow ( projectId : string ) : Promise < CxCommandOutput > {
147142 const commands : string [ ] = [ CxConstants . CMD_PROJECT , CxConstants . SUB_CMD_SHOW , CxConstants . PROJECT_ID , projectId ] ;
148143 commands . push ( ...this . initializeCommands ( true ) ) ;
149144 const exec = new ExecutionService ( ) ;
150- return await exec . executeCommands ( this . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
145+ return await exec . executeCommands ( this . config . pathToExecutable , commands , CxConstants . PROJECT_TYPE ) ;
151146 }
152147
153148 async getResultsList ( scanId : string ) {
154149 const exec = new ExecutionService ( ) ;
155150 const fileName = new Date ( ) . getTime ( ) . toString ( ) ;
156151 const commands = this . createResultCommand ( scanId , CxConstants . FORMAT_JSON , fileName , os . tmpdir ( ) )
157152 // Executes the command and creates a result file
158- await exec . executeResultsCommands ( this . pathToExecutable , commands )
153+ await exec . executeResultsCommands ( this . config . pathToExecutable , commands )
159154 // Reads the result file and retrieves the results
160- return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . pathToExecutable , fileName ) ;
155+ return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_JSON , CxConstants . FORMAT_JSON_FILE , commands , this . config . pathToExecutable , fileName ) ;
161156 }
162157
163158 async getResultsSummary ( scanId : string ) : Promise < CxCommandOutput > {
164159 const exec = new ExecutionService ( ) ;
165160 const fileName = new Date ( ) . getTime ( ) . toString ( ) ;
166161 const commands = this . createResultCommand ( scanId , CxConstants . FORMAT_HTML_CLI , fileName , os . tmpdir ( ) ) ;
167162 // Executes the command and creates a result file
168- await exec . executeResultsCommands ( this . pathToExecutable , commands ) ;
163+ await exec . executeResultsCommands ( this . config . pathToExecutable , commands ) ;
169164 // Reads the result file and retrieves the results
170- return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_HTML , CxConstants . FORMAT_HTML_FILE , commands , this . pathToExecutable , fileName ) ;
165+ return exec . executeResultsCommandsFile ( scanId , CxConstants . FORMAT_HTML , CxConstants . FORMAT_HTML_FILE , commands , this . config . pathToExecutable , fileName ) ;
171166 }
172167
173168 async getResults ( scanId : string , resultType :string , outputFileName : string , outputFilePath : string ) {
174169 const commands = this . createResultCommand ( scanId , resultType , outputFileName , outputFilePath )
175170 const exec = new ExecutionService ( ) ;
176- return await exec . executeCommands ( this . pathToExecutable , commands ) ;
171+ return await exec . executeCommands ( this . config . pathToExecutable , commands ) ;
177172 }
178173
179174 createResultCommand ( scanId : string , reportFormat : string , outputFileName : string , outputPath : string ) : string [ ] {
0 commit comments