@@ -28,14 +28,18 @@ import {
28
28
AuthMethodsConfiguration ,
29
29
Configuration ,
30
30
createConfiguration ,
31
+ Observable ,
31
32
SecurityAuthentication ,
32
33
ServerConfiguration ,
33
34
} from './gen/index.js' ;
35
+ import { ResponseContext } from './gen/http/http.js' ;
34
36
import { OpenIDConnectAuth } from './oidc_auth.js' ;
35
37
import WebSocket from 'isomorphic-ws' ;
36
38
import child_process from 'node:child_process' ;
37
39
import { SocksProxyAgent } from 'socks-proxy-agent' ;
38
40
import { HttpProxyAgent , HttpProxyAgentOptions , HttpsProxyAgent , HttpsProxyAgentOptions } from 'hpagent' ;
41
+ import fetch from 'node-fetch' ;
42
+ import { from } from './gen/rxjsStub.js' ;
39
43
40
44
const SERVICEACCOUNT_ROOT : string = '/var/run/secrets/kubernetes.io/serviceaccount' ;
41
45
const SERVICEACCOUNT_CA_PATH : string = SERVICEACCOUNT_ROOT + '/ca.crt' ;
@@ -473,7 +477,12 @@ export class KubeConfig implements SecurityAuthentication {
473
477
) ;
474
478
}
475
479
476
- public makeApiClient < T extends ApiType > ( apiClientType : ApiConstructor < T > ) : T {
480
+ public makeApiClient < T extends ApiType > (
481
+ apiClientType : ApiConstructor < T > ,
482
+ options ?: {
483
+ timeoutMs ?: number ;
484
+ } ,
485
+ ) : T {
477
486
const cluster = this . getCurrentCluster ( ) ;
478
487
if ( ! cluster ) {
479
488
throw new Error ( 'No active cluster!' ) ;
@@ -485,6 +494,35 @@ export class KubeConfig implements SecurityAuthentication {
485
494
const config : Configuration = createConfiguration ( {
486
495
baseServer : baseServerConfig ,
487
496
authMethods : authConfig ,
497
+ // This HTTP API implementation is a copy of ./gen/http/isomorphic-fetch.ts,
498
+ // extended with the timeout pass-through code.
499
+ httpApi : {
500
+ send ( request : RequestContext ) : Observable < ResponseContext > {
501
+ const method = request . getHttpMethod ( ) . toString ( ) ;
502
+ const body = request . getBody ( ) ;
503
+
504
+ const resultPromise = fetch ( request . getUrl ( ) , {
505
+ method : method ,
506
+ body : body as any ,
507
+ headers : request . getHeaders ( ) ,
508
+ agent : request . getAgent ( ) ,
509
+ timeout : options ?. timeoutMs ,
510
+ } ) . then ( ( resp : any ) => {
511
+ const headers : { [ name : string ] : string } = { } ;
512
+ resp . headers . forEach ( ( value : string , name : string ) => {
513
+ headers [ name ] = value ;
514
+ } ) ;
515
+
516
+ const body = {
517
+ text : ( ) => resp . text ( ) ,
518
+ binary : ( ) => resp . buffer ( ) ,
519
+ } ;
520
+ return new ResponseContext ( resp . status , headers , body ) ;
521
+ } ) ;
522
+
523
+ return from < Promise < ResponseContext > > ( resultPromise ) ;
524
+ } ,
525
+ } ,
488
526
} ) ;
489
527
490
528
const apiClient = new apiClientType ( config ) ;
0 commit comments