@@ -37,28 +37,32 @@ type PluginFunc<T> = (plugin: ConnectionPlugin, targetFunc: () => Promise<T>) =>
3737
3838class PluginChain < T > {
3939 private readonly targetFunc : ( ) => Promise < T > ;
40- private chain ?: ( pluginFunc : PluginFunc < T > , targetFunc : ( ) => Promise < T > ) => Promise < T > ;
40+ private chain ?: ( pluginFunc : PluginFunc < T > , targetFunc : ( ) => Promise < T > , pluginToSkip : ConnectionPlugin | null ) => Promise < T > ;
4141
4242 constructor ( targetFunc : ( ) => Promise < T > ) {
4343 this . targetFunc = targetFunc ;
4444 }
4545
46- addToHead ( plugin : ConnectionPlugin ) {
46+ addToHead ( plugin : ConnectionPlugin , pluginToSkip : ConnectionPlugin | null ) {
4747 if ( this . chain === undefined ) {
48- this . chain = ( pluginFunc , targetFunc ) => pluginFunc ( plugin , targetFunc ) ;
48+ this . chain = ( pluginFunc , targetFunc , pluginToSkip ) => pluginFunc ( plugin , targetFunc ) ;
4949 } else {
5050 const pipelineSoFar = this . chain ;
5151 // @ts -ignore
52- this . chain = ( pluginFunc , targetFunc ) => pluginFunc ( plugin , ( ) => pipelineSoFar ( pluginFunc , targetFunc ) ) ;
52+ if ( plugin !== pluginToSkip ) {
53+ this . chain = ( pluginFunc , targetFunc , pluginToSkip ) => {
54+ return pluginFunc ( plugin , ( ) => pipelineSoFar ( pluginFunc , targetFunc , pluginToSkip ) ) ;
55+ } ;
56+ }
5357 }
5458 return this ;
5559 }
5660
57- execute ( pluginFunc : PluginFunc < T > ) : Promise < T > {
61+ execute ( pluginFunc : PluginFunc < T > , pluginToSkip : ConnectionPlugin | null ) : Promise < T > {
5862 if ( this . chain === undefined ) {
5963 throw new AwsWrapperError ( Messages . get ( "PluginManager.pipelineNone" ) ) ;
6064 }
61- return this . chain ( pluginFunc , this . targetFunc ) ;
65+ return this . chain ( pluginFunc , this . targetFunc , pluginToSkip ) ;
6266 }
6367}
6468
@@ -133,15 +137,28 @@ export class PluginManager {
133137 props ,
134138 methodName ,
135139 ( plugin , nextPluginFunc ) => this . runMethodFuncWithTelemetry ( ( ) => plugin . execute ( methodName , nextPluginFunc , options ) , plugin . name ) ,
136- methodFunc
140+ methodFunc ,
141+ null
137142 ) ;
138143 } ) ;
139144 } finally {
140145 this . pluginServiceManagerContainer . pluginService . attachErrorListener ( currentClient ) ;
141146 }
142147 }
143148
144- async connect ( hostInfo : HostInfo | null , props : Map < string , any > , isInitialConnection : boolean ) : Promise < ClientWrapper > {
149+ async connect ( hostInfo : HostInfo | null , props : Map < string , any > , isInitialConnection : boolean ) : Promise < ClientWrapper > ;
150+ async connect (
151+ hostInfo : HostInfo | null ,
152+ props : Map < string , any > ,
153+ isInitialConnection : boolean ,
154+ pluginToSkip : ConnectionPlugin | null
155+ ) : Promise < ClientWrapper > ;
156+ async connect (
157+ hostInfo : HostInfo | null ,
158+ props : Map < string , any > ,
159+ isInitialConnection : boolean ,
160+ pluginToSkip ?: ConnectionPlugin | null
161+ ) : Promise < ClientWrapper > {
145162 if ( hostInfo == null ) {
146163 throw new AwsWrapperError ( Messages . get ( "HostInfo.noHostParameter" ) ) ;
147164 }
@@ -156,12 +173,25 @@ export class PluginManager {
156173 this . runMethodFuncWithTelemetry ( ( ) => plugin . connect ( hostInfo , props , isInitialConnection , nextPluginFunc ) , plugin . name ) ,
157174 async ( ) => {
158175 throw new AwsWrapperError ( "Shouldn't be called." ) ;
159- }
176+ } ,
177+ pluginToSkip
160178 ) ;
161179 } ) ;
162180 }
163181
164- async forceConnect ( hostInfo : HostInfo | null , props : Map < string , any > , isInitialConnection : boolean ) : Promise < ClientWrapper > {
182+ async forceConnect ( hostInfo : HostInfo | null , props : Map < string , any > , isInitialConnection : boolean ) : Promise < ClientWrapper > ;
183+ async forceConnect (
184+ hostInfo : HostInfo | null ,
185+ props : Map < string , any > ,
186+ isInitialConnection : boolean ,
187+ pluginToSkip : ConnectionPlugin | null
188+ ) : Promise < ClientWrapper > ;
189+ async forceConnect (
190+ hostInfo : HostInfo | null ,
191+ props : Map < string , any > ,
192+ isInitialConnection : boolean ,
193+ pluginToSkip ?: ConnectionPlugin | null
194+ ) : Promise < ClientWrapper > {
165195 if ( hostInfo == null ) {
166196 throw new AwsWrapperError ( Messages . get ( "HostInfo.noHostParameter" ) ) ;
167197 }
@@ -176,7 +206,8 @@ export class PluginManager {
176206 this . runMethodFuncWithTelemetry ( ( ) => plugin . forceConnect ( hostInfo , props , isInitialConnection , nextPluginFunc ) , plugin . name ) ,
177207 async ( ) => {
178208 throw new AwsWrapperError ( "Shouldn't be called." ) ;
179- }
209+ } ,
210+ pluginToSkip
180211 ) ;
181212 } ) ;
182213 }
@@ -186,19 +217,26 @@ export class PluginManager {
186217 props : Map < string , any > ,
187218 methodName : string ,
188219 pluginFunc : PluginFunc < T > ,
189- methodFunc : ( ) => Promise < T >
220+ methodFunc : ( ) => Promise < T > ,
221+ pluginToSkip : ConnectionPlugin | null
190222 ) : Promise < T > {
191- const chain = this . makeExecutePipeline ( hostInfo , props , methodName , methodFunc ) ;
192- return chain . execute ( pluginFunc ) ;
223+ const chain = this . makeExecutePipeline ( hostInfo , props , methodName , methodFunc , pluginToSkip ) ;
224+ return chain . execute ( pluginFunc , pluginToSkip ) ;
193225 }
194226
195- makeExecutePipeline < T > ( hostInfo : HostInfo , props : Map < string , any > , name : string , methodFunc : ( ) => Promise < T > ) : PluginChain < T > {
227+ makeExecutePipeline < T > (
228+ hostInfo : HostInfo ,
229+ props : Map < string , any > ,
230+ name : string ,
231+ methodFunc : ( ) => Promise < T > ,
232+ pluginToSkip : ConnectionPlugin | null
233+ ) : PluginChain < T > {
196234 const chain = new PluginChain ( methodFunc ) ;
197235
198236 for ( let i = this . _plugins . length - 1 ; i >= 0 ; i -- ) {
199237 const p = this . _plugins [ i ] ;
200238 if ( p . getSubscribedMethods ( ) . has ( "*" ) || p . getSubscribedMethods ( ) . has ( name ) ) {
201- chain . addToHead ( p ) ;
239+ chain . addToHead ( p , pluginToSkip ) ;
202240 }
203241 }
204242
@@ -219,7 +257,8 @@ export class PluginManager {
219257 ) ,
220258 ( ) => {
221259 throw new AwsWrapperError ( "Shouldn't be called" ) ;
222- }
260+ } ,
261+ null
223262 ) ;
224263 } ) ;
225264 }
0 commit comments