@@ -14,7 +14,6 @@ export class CxAuth {
1414 clientId : string = "" ;
1515 clientSecret : string = "" ;
1616 apiKey : string = "" ;
17- commands : string [ ] = [ ] ;
1817 pathToExecutable : string ;
1918 tenant : string ;
2019
@@ -56,7 +55,7 @@ export class CxAuth {
5655 }
5756
5857 initializeCommands ( formatRequired : boolean ) : string [ ] {
59- let list : string [ ] = [ ] ;
58+ const list : string [ ] = [ ] ;
6059 if ( this . clientId ) {
6160 list . push ( "--client-id" ) ;
6261 list . push ( this . clientId ) ;
@@ -80,35 +79,33 @@ export class CxAuth {
8079 if ( formatRequired ) {
8180 list . push ( "--format" ) ;
8281 list . push ( "json" ) ;
83- list . push ( "-v" ) ;
8482 }
8583 return list ;
8684 }
8785
8886 async scanCreate ( params : ParamTypeMap ) : Promise < CxCommandOutput > {
89- this . commands = this . initializeCommands ( true ) ;
90- this . commands . push ( "scan" ) ;
91- this . commands . push ( "create" ) ;
87+ const commands : string [ ] = [ "scan" , "create" ] ;
88+ commands . push ( ...this . initializeCommands ( true ) ) ;
9289 params . forEach ( ( value : string , key : CxParamType ) => {
9390 if ( key !== CxParamType . ADDITIONAL_PARAMETERS && key . length !== 1 && value ) {
94- this . commands . push ( "--" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
95- this . commands . push ( value ) ;
91+ commands . push ( "--" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
92+ commands . push ( value ) ;
9693 } else if ( key . length === 1 && value ) {
97- this . commands . push ( "-" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
98- this . commands . push ( value ) ;
94+ commands . push ( "-" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
95+ commands . push ( value ) ;
9996 } else if ( key === CxParamType . ADDITIONAL_PARAMETERS ) {
10097 let paramList = value . match ( / (?: [ ^ \s " ] + | " [ ^ " ] * " ) + / g) ;
10198 console . log ( "Additional parameters refined: " + paramList )
10299 if ( paramList ) {
103100 paramList . forEach ( ( element ) => {
104- this . commands . push ( element ) ;
101+ commands . push ( element ) ;
105102 } ) ;
106103 }
107104 }
108105 } ) ;
109106
110- let exec = new ExecutionService ( ) ;
111- return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
107+ const exec = new ExecutionService ( ) ;
108+ return await exec . executeCommands ( this . pathToExecutable , commands ) ;
112109 }
113110
114111 async authValidate ( ) : Promise < CxCommandOutput > {
@@ -120,29 +117,27 @@ export class CxAuth {
120117 }
121118
122119 async scanShow ( id : string ) : Promise < CxCommandOutput > {
123- this . commands = this . initializeCommands ( true ) ;
124- this . commands . push ( "scan" ) ;
125- this . commands . push ( "show" ) ;
126- this . commands . push ( "--scan-id" ) ;
127- this . commands . push ( id ) ;
128- let exec = new ExecutionService ( ) ;
129- return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
120+ const commands : string [ ] = [ "scan" , "show" , "--scan-id" , id ] ;
121+ commands . push ( ...this . initializeCommands ( true ) ) ;
122+
123+ const exec = new ExecutionService ( ) ;
124+ return await exec . executeCommands ( this . pathToExecutable , commands ) ;
130125 }
131126
132127 async scanList ( ) : Promise < CxCommandOutput > {
133- this . commands = this . initializeCommands ( true ) ;
134- this . commands . push ( "scan" ) ;
135- this . commands . push ( "list" ) ;
136- let exec = new ExecutionService ( ) ;
137- return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
128+ const commands : string [ ] = [ "scan" , "list" ] ;
129+ commands . push ( ... this . initializeCommands ( true ) ) ;
130+
131+ const exec = new ExecutionService ( ) ;
132+ return await exec . executeCommands ( this . pathToExecutable , commands ) ;
138133 }
139134
140135 async projectList ( ) : Promise < CxCommandOutput > {
141- this . commands = this . initializeCommands ( true ) ;
142- this . commands . push ( "project" ) ;
143- this . commands . push ( "list" ) ;
144- let exec = new ExecutionService ( ) ;
145- return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
136+ const commands : string [ ] = [ "project" , "list" ] ;
137+ commands . push ( ... this . initializeCommands ( true ) ) ;
138+
139+ const exec = new ExecutionService ( ) ;
140+ return await exec . executeCommands ( this . pathToExecutable , commands ) ;
146141 }
147142
148143 async getResultsList ( scanId : string ) {
@@ -154,42 +149,38 @@ export class CxAuth {
154149 }
155150
156151 async getResults ( scanId : string , resultType :string , outputFileName : string , outputFilePath : string ) {
157- this . commands = this . createResultCommand ( scanId , resultType , outputFileName , outputFilePath )
152+ const commands = this . createResultCommand ( scanId , resultType , outputFileName , outputFilePath )
158153
159154 const exec = new ExecutionService ( ) ;
160- return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
155+ return await exec . executeCommands ( this . pathToExecutable , commands ) ;
161156 }
162157
163158 async executeResultsCommands ( scanId : string , resultType : string , fileExtension : string ) : Promise < string > {
164159 const fileName = new Date ( ) . getTime ( ) . toString ( ) ;
165- this . commands = this . createResultCommand ( scanId , resultType , fileName , os . tmpdir ( ) )
160+ const commands = this . createResultCommand ( scanId , resultType , fileName , os . tmpdir ( ) )
166161
167162 const exec = new ExecutionService ( ) ;
168- await exec . executeResultsCommands ( this . pathToExecutable , this . commands )
163+ await exec . executeResultsCommands ( this . pathToExecutable , commands )
169164
170165 const filePath = path . join ( os . tmpdir ( ) , fileName + fileExtension )
171166
172167 return fs . readFileSync ( filePath , 'utf8' ) ;
173168 }
174169
175170 createResultCommand ( scanId : string , reportFormat : string , outputFileName : string , outputPath : string ) : string [ ] {
176- const resultCommands = this . initializeCommands ( false ) ;
177- resultCommands . push ( "result" ) ;
178- resultCommands . push ( "--scan-id" ) ;
179- resultCommands . push ( scanId ) ;
180- resultCommands . push ( "--report-format" ) ;
181- resultCommands . push ( reportFormat ) ;
171+ const commands : string [ ] = [ "result" , "--scan-id" , scanId , "--report-format" , reportFormat ] ;
182172
183173 if ( outputFileName ) {
184- resultCommands . push ( "--output-name" )
185- resultCommands . push ( outputFileName )
174+ commands . push ( "--output-name" )
175+ commands . push ( outputFileName )
186176 }
187177 if ( outputPath ) {
188- resultCommands . push ( "--output-path" )
189- resultCommands . push ( outputPath )
178+ commands . push ( "--output-path" )
179+ commands . push ( outputPath )
190180 }
181+ commands . push ( ...this . initializeCommands ( false ) ) ;
191182
192- return resultCommands ;
183+ return commands ;
193184 }
194185}
195186
0 commit comments