@@ -13,7 +13,7 @@ import {Semaphore} from "async-mutex";
1313type ParamTypeMap = Map < CxParamType , string > ;
1414
1515export class CxWrapper {
16- private static instance : CxWrapper ;
16+ private static instances = new Map < string , CxWrapper > ( ) ;
1717 private static semaphore = new Semaphore ( 1 ) ; // Semaphore with 1 slot
1818 config : CxConfig ;
1919 cxInstaller : CxInstaller ;
@@ -51,12 +51,19 @@ export class CxWrapper {
5151
5252 static async getInstance ( cxScanConfig : CxConfig , logFilePath : string ) : Promise < CxWrapper > {
5353 const [ _ , release ] = await this . semaphore . acquire ( ) ;
54- if ( ! CxWrapper . instance ) {
55- CxWrapper . instance = new CxWrapper ( cxScanConfig , logFilePath ) ;
54+ let key = this . generateKey ( cxScanConfig , logFilePath ) ;
55+ let wrapper = CxWrapper . instances . get ( key ) ;
56+ if ( ! wrapper ) {
57+ wrapper = new CxWrapper ( cxScanConfig , logFilePath ) ;
58+ CxWrapper . instances . set ( key , wrapper ) ;
5659 }
5760 release ( ) ;
5861
59- return CxWrapper . instance ;
62+ return wrapper ;
63+ }
64+
65+ static generateKey ( config :CxConfig , logFilePath :string ) : string {
66+ return `${ config . baseUri } ${ config . baseAuthUri } ${ config . clientId } ${ config . clientSecret } ${ config . apiKey } ${ config . tenant } ${ config . additionalParameters } ${ config . pathToExecutable } ${ logFilePath } ` . toLowerCase ( ) ;
6067 }
6168
6269 async init ( ) : Promise < void > {
0 commit comments