@@ -12,7 +12,6 @@ import { Disposable } from "@gitpod/gitpod-protocol";
1212import { WorkspaceClusterWoTls , WorkspaceManagerConnectionInfo } from '@gitpod/gitpod-protocol/lib/workspace-cluster' ;
1313import { WorkspaceManagerClientProviderCompositeSource , WorkspaceManagerClientProviderSource } from "./client-provider-source" ;
1414import { log } from '@gitpod/gitpod-protocol/lib/util/logging' ;
15- import { GetWorkspacesRequest } from "./core_pb" ;
1615
1716@injectable ( )
1817export class WorkspaceManagerClientProvider implements Disposable {
@@ -56,14 +55,14 @@ export class WorkspaceManagerClientProvider implements Disposable {
5655 let client = this . connectionCache . get ( name ) ;
5756 if ( ! client ) {
5857 const info = await getConnectionInfo ( ) ;
59- client = createClient ( info , grpcOptions ) ;
58+ client = this . createClient ( info , grpcOptions ) ;
6059 this . connectionCache . set ( name , client ) ;
6160 } else if ( client . getChannel ( ) . getConnectivityState ( true ) != grpc . connectivityState . READY ) {
6261 client . close ( ) ;
6362
6463 console . warn ( `Lost connection to workspace manager \"${ name } \" - attempting to reestablish` ) ;
6564 const info = await getConnectionInfo ( ) ;
66- client = createClient ( info , grpcOptions ) ;
65+ client = this . createClient ( info , grpcOptions ) ;
6766 this . connectionCache . set ( name , client ) ;
6867 }
6968
@@ -78,39 +77,30 @@ export class WorkspaceManagerClientProvider implements Disposable {
7877 return this . source . getAllWorkspaceClusters ( ) ;
7978 }
8079
81- /**
82- * Tries to establish a gRPC connection to the specified target. Throws an exception if it fails.
83- * @param info
84- */
85- public async tryConnectTo ( info : WorkspaceManagerConnectionInfo ) {
86- const client = new PromisifiedWorkspaceManagerClient ( createClient ( info ) ) ;
87- await client . getWorkspaces ( { } , new GetWorkspacesRequest ( ) ) ;
80+ public createClient ( info : WorkspaceManagerConnectionInfo , grpcOptions ?: object ) : WorkspaceManagerClient {
81+ let credentials : grpc . ChannelCredentials ;
82+ if ( info . tls ) {
83+ const rootCerts = Buffer . from ( info . tls . ca , "base64" ) ;
84+ const privateKey = Buffer . from ( info . tls . key , "base64" ) ;
85+ const certChain = Buffer . from ( info . tls . crt , "base64" ) ;
86+ credentials = grpc . credentials . createSsl ( rootCerts , privateKey , certChain ) ;
87+ log . debug ( "using TLS config to connect ws-manager" ) ;
88+ } else {
89+ credentials = grpc . credentials . createInsecure ( ) ;
90+ }
91+
92+ const options = {
93+ ...grpcOptions ,
94+ 'grpc.ssl_target_name_override' : "ws-manager" , // this makes sure we can call ws-manager with a URL different to "ws-manager"
95+ } ;
96+ return new WorkspaceManagerClient ( info . url , credentials , options ) ;
8897 }
8998
9099 public dispose ( ) {
91100 Array . from ( this . connectionCache . values ( ) ) . map ( c => c . close ( ) ) ;
92101 }
93102}
94103
95- function createClient ( info : WorkspaceManagerConnectionInfo , grpcOptions ?: object ) : WorkspaceManagerClient {
96- let credentials : grpc . ChannelCredentials ;
97- if ( info . tls ) {
98- const rootCerts = Buffer . from ( info . tls . ca , "base64" ) ;
99- const privateKey = Buffer . from ( info . tls . key , "base64" ) ;
100- const certChain = Buffer . from ( info . tls . crt , "base64" ) ;
101- credentials = grpc . credentials . createSsl ( rootCerts , privateKey , certChain ) ;
102- log . debug ( "using TLS config to connect ws-manager" ) ;
103- } else {
104- credentials = grpc . credentials . createInsecure ( ) ;
105- }
106-
107- const options = {
108- ...grpcOptions ,
109- 'grpc.ssl_target_name_override' : "ws-manager" , // this makes sure we can call ws-manager with a URL different to "ws-manager"
110- } ;
111- return new WorkspaceManagerClient ( info . url , credentials , options ) ;
112- }
113-
114104/**
115105 *
116106 * @param clusters
0 commit comments