11import 'regenerator-runtime/runtime'
2- import { CxScanConfigCall } from "./CxScanConfigCall " ;
2+ import { CxScanConfig } from "./CxScanConfig " ;
33import { CxParamType } from "./CxParamType" ;
44import { ExecutionService } from "./ExecutionService" ;
55import { spawn } from "child_process" ;
66import { CxResultType } from "./CxResultType" ;
7+ import { CxCommandOutput } from "./CxCommandOutput" ;
78
89type ParamTypeMap = Map < CxParamType , string > ;
910
10- export class CxAuthCall {
11+ export class CxAuth {
1112 baseUri : string = "" ;
1213 clientId : string = "" ;
1314 clientSecret : string = "" ;
1415 apiKey : string = "" ;
1516 commands : string [ ] = [ ] ;
1617 pathToExecutable : string ;
1718
18- constructor ( cxScanConfig : CxScanConfigCall ) {
19+ constructor ( cxScanConfig : CxScanConfig ) {
1920 let path = require ( "path" ) ;
20- if ( cxScanConfig . clientId !== null && cxScanConfig . clientSecret !== null ) {
21+ if ( cxScanConfig . clientId !== null && cxScanConfig . clientSecret !== null && cxScanConfig . clientId !== '' && cxScanConfig . clientId !== '' ) {
2122 console . log ( "Received clientId and clientSecret" ) ;
2223 this . clientId = cxScanConfig . clientId ;
2324 this . clientSecret = cxScanConfig . clientSecret ;
2425 } else if ( cxScanConfig . apiKey != null ) {
2526 this . apiKey = cxScanConfig . apiKey ;
2627 } else {
27- console . log ( "Did not receive ClientId/Secret or ApiKey" ) ;
28+ console . log ( "Did not receive ClientId/Secret or ApiKey from cli arguments " ) ;
2829 }
2930 let executablePath : string ;
31+
32+
3033 if ( cxScanConfig . pathToExecutable !== null && cxScanConfig . pathToExecutable !== "" ) {
3134 this . pathToExecutable = cxScanConfig . pathToExecutable ;
3235 } else if ( process . platform === 'win32' ) {
@@ -40,26 +43,26 @@ export class CxAuthCall {
4043 executablePath = path . join ( __dirname , '/resources/cx-linux' ) ;
4144 this . pathToExecutable = executablePath ;
4245 }
43- if ( cxScanConfig . baseUri !== null ) {
46+ if ( cxScanConfig . baseUri !== null && cxScanConfig . baseUri !== '' ) {
4447 this . baseUri = cxScanConfig . baseUri ;
4548 }
4649 }
4750
4851 initializeCommands ( formatRequired : boolean ) : string [ ] {
4952 let list : string [ ] = [ ] ;
50- if ( this . clientId !== null && this . clientId !== "" ) {
53+ if ( this . clientId !== null && this . clientId . length > 1 ) {
5154 list . push ( "--client-id" ) ;
5255 list . push ( this . clientId ) ;
5356 }
54- if ( this . clientSecret !== null && this . clientSecret !== "" ) {
57+ if ( this . clientSecret !== null && this . clientSecret . length > 1 ) {
5558 list . push ( "--client-secret" ) ;
5659 list . push ( this . clientSecret ) ;
5760 }
58- if ( this . apiKey !== null && this . apiKey !== "" ) {
61+ if ( this . apiKey !== null && this . apiKey . length > 1 ) {
5962 list . push ( "--apikey" ) ;
6063 list . push ( this . apiKey ) ;
6164 }
62- if ( this . baseUri !== null && this . baseUri !== "" ) {
65+ if ( this . baseUri !== null && this . baseUri . length > 1 ) {
6366 list . push ( "--base-uri" ) ;
6467 list . push ( this . baseUri ) ;
6568 }
@@ -71,18 +74,18 @@ export class CxAuthCall {
7174 return list ;
7275 }
7376
74- async scanCreate ( params : ParamTypeMap ) : Promise < string > {
77+ async scanCreate ( params : ParamTypeMap ) : Promise < CxCommandOutput > {
7578 this . commands = this . initializeCommands ( true ) ;
7679 this . commands . push ( "scan" ) ;
7780 this . commands . push ( "create" ) ;
7881 params . forEach ( ( value : string , key : CxParamType ) => {
79- if ( key !== CxParamType . ADDITIONAL_PARAMETERS && key . length !== 1 ) {
82+ if ( key !== CxParamType . ADDITIONAL_PARAMETERS && key . length !== 1 && value !== null && value !== undefined && value . length > 1 ) {
8083 this . commands . push ( "--" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
8184 this . commands . push ( value ) ;
82- } else if ( key . length === 1 ) {
85+ } else if ( key . length === 1 && value !== null && value !== undefined ) {
8386 this . commands . push ( "-" + key . toString ( ) . replace ( / _ / g, "-" ) . toLowerCase ( ) ) ;
8487 this . commands . push ( value ) ;
85- } else {
88+ } else if ( key === CxParamType . ADDITIONAL_PARAMETERS ) {
8689 let paramList = value . match ( / (?: [ ^ \s " ] + | " [ ^ " ] * " ) + / g) ;
8790 console . log ( "Additional parameters refined: " + paramList )
8891 if ( paramList !== null ) {
@@ -97,24 +100,25 @@ export class CxAuthCall {
97100 return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
98101 }
99102
100- async scanShow ( id : string ) : Promise < string > {
103+ async scanShow ( id : string ) : Promise < CxCommandOutput > {
101104 this . commands = this . initializeCommands ( true ) ;
102105 this . commands . push ( "scan" ) ;
103106 this . commands . push ( "show" ) ;
107+ this . commands . push ( "--scan-id" ) ;
104108 this . commands . push ( id ) ;
105109 let exec = new ExecutionService ( ) ;
106110 return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
107111 }
108112
109- async scanList ( ) : Promise < string > {
113+ async scanList ( ) : Promise < CxCommandOutput > {
110114 this . commands = this . initializeCommands ( true ) ;
111115 this . commands . push ( "scan" ) ;
112116 this . commands . push ( "list" ) ;
113117 let exec = new ExecutionService ( ) ;
114118 return await exec . executeCommands ( this . pathToExecutable , this . commands ) ;
115119 }
116120
117- async projectList ( ) : Promise < string > {
121+ async projectList ( ) : Promise < CxCommandOutput > {
118122 this . commands = this . initializeCommands ( true ) ;
119123 this . commands . push ( "project" ) ;
120124 this . commands . push ( "list" ) ;
0 commit comments