1
1
import * as grpc from "@grpc/grpc-js" ;
2
2
import { 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" ;
4
6
5
7
// NOTE: Copied from channel-credentials.ts in gRPC Node package because its not exported:
6
8
// https://github.com/grpc/grpc-node/blob/3106057f5ad8f79a71d2ae411e116ad308a2e835/packages/grpc-js/src/call-credentials.ts#L143
7
9
class ComposedChannelCredentials extends grpc . ChannelCredentials {
8
10
constructor (
9
11
private channelCredentials : KnownInsecureChannelCredentialsImpl ,
10
- callCreds : grpc . CallCredentials
12
+ private callCreds : grpc . CallCredentials
11
13
) {
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
+ */
13
21
}
14
22
compose ( callCredentials : grpc . CallCredentials ) {
15
23
const combinedCallCredentials =
16
- this . callCredentials . compose ( callCredentials ) ;
24
+ this . callCreds . compose ( callCredentials ) ;
17
25
return new ComposedChannelCredentials (
18
26
this . channelCredentials ,
19
27
combinedCallCredentials
20
28
) ;
21
29
}
22
-
23
- _getConnectionOptions ( ) : ConnectionOptions | null {
24
- return this . channelCredentials . _getConnectionOptions ( ) ;
25
- }
26
30
_isSecure ( ) : boolean {
27
31
return false ;
28
32
}
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
+
29
50
_equals ( other : grpc . ChannelCredentials ) : boolean {
30
51
if ( this === other ) {
31
52
return true ;
32
53
}
33
54
if ( other instanceof ComposedChannelCredentials ) {
34
55
return (
35
56
this . channelCredentials . _equals ( other . channelCredentials ) &&
36
- this . callCredentials . _equals ( other . callCredentials )
57
+ this . callCreds . _equals ( other . callCreds )
37
58
) ;
38
59
} else {
39
60
return false ;
@@ -44,25 +65,32 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials {
44
65
// Create our own known insecure channel creds.
45
66
// See https://github.com/grpc/grpc-node/issues/543 for why this is necessary.
46
67
class KnownInsecureChannelCredentialsImpl extends grpc . ChannelCredentials {
47
- constructor ( callCredentials ?: grpc . CallCredentials ) {
48
- super ( callCredentials ) ;
49
- }
50
68
51
69
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 ) ;
55
71
}
56
72
57
- _getConnectionOptions ( ) : ConnectionOptions {
58
- return { } ;
59
- }
60
73
_isSecure ( ) : boolean {
61
74
return false ;
62
75
}
63
76
_equals ( other : grpc . ChannelCredentials ) : boolean {
64
77
return other instanceof KnownInsecureChannelCredentialsImpl ;
65
78
}
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
+ }
66
94
}
67
95
68
96
export enum ClientSecurity {
0 commit comments