Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/v1/example.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { v1 } from '@authzed/authzed-node';
const { promises: promiseClient } = client; // access client.promises
// set up it on localhost like this:
// const client = v1.NewClient('mytokenhere', 'localhost:50051', 1);
const client = v1.NewClient('mytokenhere');
const { promises: promiseClient } = client; // access client.promises after instantiating client

const writeRequest = v1.WriteSchemaRequest.create({
schema: `definition test/user {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build-js-client": "tsc --declaration false --outDir js-dist"
},
"dependencies": {
"@grpc/grpc-js": "~1.12.5",
"@grpc/grpc-js": "^1.12.5",
Comment thread
tstirrat15 marked this conversation as resolved.
Outdated
"@protobuf-ts/runtime": "^2.9.6",
"@protobuf-ts/runtime-rpc": "^2.9.6",
"google-protobuf": "^3.21.4"
Expand Down
64 changes: 46 additions & 18 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
import * as grpc from "@grpc/grpc-js";
import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors.js";
import { ConnectionOptions } from "tls";
import * as net from "net";
import { SecureConnector } from "@grpc/grpc-js/build/src/channel-credentials.js";
import { GrpcUri } from "@grpc/grpc-js/build/src/uri-parser.js";

// NOTE: Copied from channel-credentials.ts in gRPC Node package because its not exported:
// https://github.com/grpc/grpc-node/blob/3106057f5ad8f79a71d2ae411e116ad308a2e835/packages/grpc-js/src/call-credentials.ts#L143
class ComposedChannelCredentials extends grpc.ChannelCredentials {
constructor(
private channelCredentials: KnownInsecureChannelCredentialsImpl,
callCreds: grpc.CallCredentials
private callCreds: grpc.CallCredentials
) {
super(callCreds);
super();
Comment thread
tstirrat15 marked this conversation as resolved.
// NOTE: leaving this here to show what changed from the upstream.
/*
if (!channelCredentials._isSecure()) {
throw new Error('Cannot compose insecure credentials');
}
*/
}
compose(callCredentials: grpc.CallCredentials) {
const combinedCallCredentials =
this.callCredentials.compose(callCredentials);
this.callCreds.compose(callCredentials);
return new ComposedChannelCredentials(
this.channelCredentials,
combinedCallCredentials
);
}

_getConnectionOptions(): ConnectionOptions | null {
return this.channelCredentials._getConnectionOptions();
}
_isSecure(): boolean {
Comment thread
tstirrat15 marked this conversation as resolved.
return false;
}

// NOTE: this is copied from the InsecureChannelCredentialsImpl class
_createSecureConnector(
Comment on lines +31 to +35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_createSecureConnector(
// NOTE: this is copied from the InsecureChannelCredentialsImpl class
_createSecureConnector(

channelTarget: GrpcUri,
options: grpc.ChannelOptions,
callCredentials?: grpc.CallCredentials
): SecureConnector {
return {
connect: async (socket: net.Socket) => {
return { socket, secure: false };
},
waitForReady: async () => {},
getCallCredentials: () => callCredentials || this.callCreds,
destroy: () => {}
};
}

_equals(other: grpc.ChannelCredentials): boolean {
if (this === other) {
return true;
}
if (other instanceof ComposedChannelCredentials) {
return (
this.channelCredentials._equals(other.channelCredentials) &&
this.callCredentials._equals(other.callCredentials)
this.callCreds._equals(other.callCreds)
);
} else {
return false;
Expand All @@ -44,25 +65,32 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials {
// Create our own known insecure channel creds.
// See https://github.com/grpc/grpc-node/issues/543 for why this is necessary.
class KnownInsecureChannelCredentialsImpl extends grpc.ChannelCredentials {
constructor(callCredentials?: grpc.CallCredentials) {
super(callCredentials);
}

compose(callCredentials: grpc.CallCredentials): grpc.ChannelCredentials {
const combinedCallCredentials =
this.callCredentials.compose(callCredentials);
return new ComposedChannelCredentials(this, combinedCallCredentials);
return new ComposedChannelCredentials(this, callCredentials);
}

_getConnectionOptions(): ConnectionOptions {
return {};
}
_isSecure(): boolean {
return false;
}
_equals(other: grpc.ChannelCredentials): boolean {
return other instanceof KnownInsecureChannelCredentialsImpl;
}

_createSecureConnector(
channelTarget: GrpcUri,
options: grpc.ChannelOptions,
callCredentials: grpc.CallCredentials
): SecureConnector {
return {
connect: async (socket: net.Socket) => {
return { socket, secure: false };
},
waitForReady: async () => {},
getCallCredentials: () => callCredentials,
destroy: () => {}
};
}
}

export enum ClientSecurity {
Expand Down
Loading