11import * as grpc from "@grpc/grpc-js" ;
22import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors.js" ;
3- import { ConnectionOptions } from "tls" ;
3+ import * as net from "net" ;
4+ import { SecureConnector } from "@grpc/grpc-js/build/src/channel-credentials.js" ;
5+ import { GrpcUri } from "@grpc/grpc-js/build/src/uri-parser.js" ;
46
57// NOTE: Copied from channel-credentials.ts in gRPC Node package because its not exported:
68// https://github.com/grpc/grpc-node/blob/3106057f5ad8f79a71d2ae411e116ad308a2e835/packages/grpc-js/src/call-credentials.ts#L143
79class ComposedChannelCredentials extends grpc . ChannelCredentials {
810 constructor (
911 private channelCredentials : KnownInsecureChannelCredentialsImpl ,
10- callCreds : grpc . CallCredentials
12+ private callCreds : grpc . CallCredentials
1113 ) {
12- super ( callCreds ) ;
14+ super ( ) ;
15+ // NOTE: leaving this here to show what changed from the upstream.
16+ /*
17+ if (!channelCredentials._isSecure()) {
18+ throw new Error('Cannot compose insecure credentials');
19+ }
20+ */
1321 }
1422 compose ( callCredentials : grpc . CallCredentials ) {
1523 const combinedCallCredentials =
16- this . callCredentials . compose ( callCredentials ) ;
24+ this . callCreds . compose ( callCredentials ) ;
1725 return new ComposedChannelCredentials (
1826 this . channelCredentials ,
1927 combinedCallCredentials
2028 ) ;
2129 }
22-
23- _getConnectionOptions ( ) : ConnectionOptions | null {
24- return this . channelCredentials . _getConnectionOptions ( ) ;
25- }
2630 _isSecure ( ) : boolean {
2731 return false ;
2832 }
33+
34+ // NOTE: this is copied from the InsecureChannelCredentialsImpl class
35+ _createSecureConnector (
36+ channelTarget : GrpcUri ,
37+ options : grpc . ChannelOptions ,
38+ callCredentials ?: grpc . CallCredentials
39+ ) : SecureConnector {
40+ return {
41+ connect : async ( socket : net . Socket ) => {
42+ return { socket, secure : false } ;
43+ } ,
44+ waitForReady : async ( ) => { } ,
45+ getCallCredentials : ( ) => callCredentials || this . callCreds ,
46+ destroy : ( ) => { }
47+ } ;
48+ }
49+
2950 _equals ( other : grpc . ChannelCredentials ) : boolean {
3051 if ( this === other ) {
3152 return true ;
3253 }
3354 if ( other instanceof ComposedChannelCredentials ) {
3455 return (
3556 this . channelCredentials . _equals ( other . channelCredentials ) &&
36- this . callCredentials . _equals ( other . callCredentials )
57+ this . callCreds . _equals ( other . callCreds )
3758 ) ;
3859 } else {
3960 return false ;
@@ -44,25 +65,32 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials {
4465// Create our own known insecure channel creds.
4566// See https://github.com/grpc/grpc-node/issues/543 for why this is necessary.
4667class KnownInsecureChannelCredentialsImpl extends grpc . ChannelCredentials {
47- constructor ( callCredentials ?: grpc . CallCredentials ) {
48- super ( callCredentials ) ;
49- }
5068
5169 compose ( callCredentials : grpc . CallCredentials ) : grpc . ChannelCredentials {
52- const combinedCallCredentials =
53- this . callCredentials . compose ( callCredentials ) ;
54- return new ComposedChannelCredentials ( this , combinedCallCredentials ) ;
70+ return new ComposedChannelCredentials ( this , callCredentials ) ;
5571 }
5672
57- _getConnectionOptions ( ) : ConnectionOptions {
58- return { } ;
59- }
6073 _isSecure ( ) : boolean {
6174 return false ;
6275 }
6376 _equals ( other : grpc . ChannelCredentials ) : boolean {
6477 return other instanceof KnownInsecureChannelCredentialsImpl ;
6578 }
79+
80+ _createSecureConnector (
81+ channelTarget : GrpcUri ,
82+ options : grpc . ChannelOptions ,
83+ callCredentials : grpc . CallCredentials
84+ ) : SecureConnector {
85+ return {
86+ connect : async ( socket : net . Socket ) => {
87+ return { socket, secure : false } ;
88+ } ,
89+ waitForReady : async ( ) => { } ,
90+ getCallCredentials : ( ) => callCredentials ,
91+ destroy : ( ) => { }
92+ } ;
93+ }
6694}
6795
6896export enum ClientSecurity {
0 commit comments