@@ -173,6 +173,7 @@ export class KubeConfig implements SecurityAuthentication {
173
173
174
174
public async applyToHTTPSOptions ( opts : https . RequestOptions | WebSocket . ClientOptions ) : Promise < void > {
175
175
const user = this . getCurrentUser ( ) ;
176
+ const cluster = this . getCurrentCluster ( ) ;
176
177
177
178
await this . applyOptions ( opts ) ;
178
179
@@ -207,7 +208,7 @@ export class KubeConfig implements SecurityAuthentication {
207
208
agentOptions . secureProtocol = opts . secureProtocol ;
208
209
agentOptions . sessionIdContext = opts . sessionIdContext ;
209
210
210
- opts . agent = new https . Agent ( agentOptions ) ;
211
+ opts . agent = this . createAgent ( cluster , agentOptions ) ;
211
212
}
212
213
213
214
/**
@@ -250,27 +251,7 @@ export class KubeConfig implements SecurityAuthentication {
250
251
agentOptions . passphrase = httpsOptions . passphrase ;
251
252
agentOptions . rejectUnauthorized = httpsOptions . rejectUnauthorized ;
252
253
253
- let agent : https . Agent | SocksProxyAgent | HttpProxyAgent | HttpsProxyAgent ;
254
-
255
- if ( cluster && cluster . proxyUrl ) {
256
- if ( cluster . proxyUrl . startsWith ( 'socks' ) ) {
257
- agent = new SocksProxyAgent ( cluster . proxyUrl , agentOptions ) ;
258
- } else if ( cluster . server . startsWith ( 'https' ) ) {
259
- const httpsProxyAgentOptions : HttpsProxyAgentOptions = agentOptions as HttpsProxyAgentOptions ;
260
- httpsProxyAgentOptions . proxy = cluster . proxyUrl ;
261
- agent = new HttpsProxyAgent ( httpsProxyAgentOptions ) ;
262
- } else if ( cluster . server . startsWith ( 'http' ) ) {
263
- const httpProxyAgentOptions : HttpProxyAgentOptions = agentOptions as HttpProxyAgentOptions ;
264
- httpProxyAgentOptions . proxy = cluster . proxyUrl ;
265
- agent = new HttpProxyAgent ( httpProxyAgentOptions ) ;
266
- } else {
267
- throw new Error ( 'Unsupported proxy type' ) ;
268
- }
269
- } else {
270
- agent = new https . Agent ( agentOptions ) ;
271
- }
272
-
273
- context . setAgent ( agent ) ;
254
+ context . setAgent ( this . createAgent ( cluster , agentOptions ) ) ;
274
255
}
275
256
276
257
/**
@@ -531,6 +512,32 @@ export class KubeConfig implements SecurityAuthentication {
531
512
return this . getContextObject ( this . currentContext ) ;
532
513
}
533
514
515
+ private createAgent (
516
+ cluster : Cluster | null ,
517
+ agentOptions : https . AgentOptions ,
518
+ ) : https . Agent | SocksProxyAgent | HttpProxyAgent | HttpsProxyAgent {
519
+ let agent : https . Agent | SocksProxyAgent | HttpProxyAgent | HttpsProxyAgent ;
520
+
521
+ if ( cluster && cluster . proxyUrl ) {
522
+ if ( cluster . proxyUrl . startsWith ( 'socks' ) ) {
523
+ agent = new SocksProxyAgent ( cluster . proxyUrl , agentOptions ) ;
524
+ } else if ( cluster . server . startsWith ( 'https' ) ) {
525
+ const httpsProxyAgentOptions : HttpsProxyAgentOptions = agentOptions as HttpsProxyAgentOptions ;
526
+ httpsProxyAgentOptions . proxy = cluster . proxyUrl ;
527
+ agent = new HttpsProxyAgent ( httpsProxyAgentOptions ) ;
528
+ } else if ( cluster . server . startsWith ( 'http' ) ) {
529
+ const httpProxyAgentOptions : HttpProxyAgentOptions = agentOptions as HttpProxyAgentOptions ;
530
+ httpProxyAgentOptions . proxy = cluster . proxyUrl ;
531
+ agent = new HttpProxyAgent ( httpProxyAgentOptions ) ;
532
+ } else {
533
+ throw new Error ( 'Unsupported proxy type' ) ;
534
+ }
535
+ } else {
536
+ agent = new https . Agent ( agentOptions ) ;
537
+ }
538
+ return agent ;
539
+ }
540
+
534
541
private applyHTTPSOptions ( opts : https . RequestOptions | WebSocket . ClientOptions ) : void {
535
542
const cluster = this . getCurrentCluster ( ) ;
536
543
const user = this . getCurrentUser ( ) ;
0 commit comments