@@ -16,21 +16,22 @@ export class CxAuth {
1616 apiKey : string = "" ;
1717 commands : string [ ] = [ ] ;
1818 pathToExecutable : string ;
19+ tenant : string ;
1920
2021 constructor ( cxScanConfig : CxScanConfig ) {
2122 let path = require ( "path" ) ;
22- if ( cxScanConfig . clientId !== null && cxScanConfig . clientSecret !== null && cxScanConfig . clientId !== '' && cxScanConfig . clientId !== '' ) {
23+ if ( cxScanConfig . clientId && cxScanConfig . clientSecret ) {
2324 console . log ( "Received clientId and clientSecret" ) ;
2425 this . clientId = cxScanConfig . clientId ;
2526 this . clientSecret = cxScanConfig . clientSecret ;
26- } else if ( cxScanConfig . apiKey != null ) {
27+ } else if ( cxScanConfig . apiKey ) {
2728 this . apiKey = cxScanConfig . apiKey ;
2829 } else {
2930 console . log ( "Did not receive ClientId/Secret or ApiKey from cli arguments" ) ;
3031 }
3132 let executablePath : string ;
3233
33- if ( cxScanConfig . pathToExecutable !== null && cxScanConfig . pathToExecutable !== "" ) {
34+ if ( cxScanConfig . pathToExecutable ) {
3435 this . pathToExecutable = cxScanConfig . pathToExecutable ;
3536 } else if ( process . platform === 'win32' ) {
3637 executablePath = path . join ( __dirname , '/resources/cx.exe' ) ;
@@ -45,29 +46,37 @@ export class CxAuth {
4546 fs . chmodSync ( this . pathToExecutable , 0o777 ) ;
4647 }
4748
48- if ( cxScanConfig . baseUri !== null && cxScanConfig . baseUri !== '' ) {
49+ if ( cxScanConfig . baseUri ) {
4950 this . baseUri = cxScanConfig . baseUri ;
5051 }
52+
53+ if ( cxScanConfig . tenant ) {
54+ this . tenant = cxScanConfig . tenant ;
55+ }
5156 }
5257
5358 initializeCommands ( formatRequired : boolean ) : string [ ] {
5459 let list : string [ ] = [ ] ;
55- if ( this . clientId !== null && this . clientId . length > 1 ) {
60+ if ( this . clientId ) {
5661 list . push ( "--client-id" ) ;
5762 list . push ( this . clientId ) ;
5863 }
59- if ( this . clientSecret !== null && this . clientSecret . length > 1 ) {
64+ if ( this . clientSecret ) {
6065 list . push ( "--client-secret" ) ;
6166 list . push ( this . clientSecret ) ;
6267 }
63- if ( this . apiKey !== null && this . apiKey . length > 1 ) {
68+ if ( this . apiKey ) {
6469 list . push ( "--apikey" ) ;
6570 list . push ( this . apiKey ) ;
6671 }
67- if ( this . baseUri !== null && this . baseUri . length > 1 ) {
72+ if ( this . baseUri ) {
6873 list . push ( "--base-uri" ) ;
6974 list . push ( this . baseUri ) ;
7075 }
76+ if ( this . tenant ) {
77+ list . push ( "--tenant" ) ;
78+ list . push ( this . tenant ) ;
79+ }
7180 if ( formatRequired ) {
7281 list . push ( "--format" ) ;
7382 list . push ( "json" ) ;
@@ -81,16 +90,16 @@ export class CxAuth {
8190 this . commands . push ( "scan" ) ;
8291 this . commands . push ( "create" ) ;
8392 params . forEach ( ( value : string , key : CxParamType ) => {
84- if ( key !== CxParamType . ADDITIONAL_PARAMETERS && key . length !== 1 && value !== null && value !== undefined && value . length > 1 ) {
93+ if ( key !== CxParamType . ADDITIONAL_PARAMETERS && key . length !== 1 && value ) {
8594 this . commands . push ( "--" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
8695 this . commands . push ( value ) ;
87- } else if ( key . length === 1 && value !== null && value !== undefined ) {
96+ } else if ( key . length === 1 && value ) {
8897 this . commands . push ( "-" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
8998 this . commands . push ( value ) ;
9099 } else if ( key === CxParamType . ADDITIONAL_PARAMETERS ) {
91100 let paramList = value . match ( / (?: [ ^ \s " ] + | " [ ^ " ] * " ) + / g) ;
92101 console . log ( "Additional parameters refined: " + paramList )
93- if ( paramList !== null ) {
102+ if ( paramList ) {
94103 paramList . forEach ( ( element ) => {
95104 this . commands . push ( element ) ;
96105 } ) ;
@@ -132,13 +141,13 @@ export class CxAuth {
132141 this . commands = this . initializeCommands ( false ) ;
133142 this . commands . push ( "result" ) ;
134143 this . commands . push ( "list" ) ;
135- if ( scanId !== null && scanId !== "" ) {
144+ if ( scanId ) {
136145 this . commands . push ( "--scan-id" )
137146 this . commands . push ( scanId )
138147 } else {
139148 console . log ( "Scan Id not provided" )
140149 }
141- if ( formatType !== null && formatType != '' ) {
150+ if ( formatType ) {
142151 this . commands . push ( "--format" )
143152 this . commands . push ( formatType )
144153 }
@@ -150,17 +159,17 @@ export class CxAuth {
150159 this . commands = this . initializeCommands ( false ) ;
151160 this . commands . push ( "result" ) ;
152161 this . commands . push ( "summary" ) ;
153- if ( scanId !== null && scanId !== "" ) {
162+ if ( scanId ) {
154163 this . commands . push ( "--scan-id" )
155164 this . commands . push ( scanId )
156165 } else {
157166 console . log ( "Scan Id not provided" )
158167 }
159- if ( formatType !== null && formatType != '' ) {
168+ if ( formatType ) {
160169 this . commands . push ( "--format" )
161170 this . commands . push ( formatType )
162171 }
163- if ( target !== null && target != '' ) {
172+ if ( target ) {
164173 this . commands . push ( "--target" )
165174 this . commands . push ( target )
166175 }
@@ -172,7 +181,7 @@ export class CxAuth {
172181 this . commands = this . initializeCommands ( false ) ;
173182 this . commands . push ( "result" ) ;
174183 this . commands . push ( resultParam ) ;
175- if ( targetPath !== null && targetPath !== "" ) {
184+ if ( targetPath ) {
176185 this . commands . push ( "--target" ) ;
177186 this . commands . push ( targetPath ) ;
178187 }
0 commit comments