Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/authorizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
createClient,
Interceptor,
} from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import {
createGrpcTransport,
Http2SessionOptions,
} from "@connectrpc/connect-node";

import { handleError, setHeader, traceMessage } from "../util/connect";
import { TopazRegistry } from "../util/serializer";
Expand Down Expand Up @@ -65,6 +68,7 @@ type AuthorizerConfig = {
caFile?: string;
insecure?: boolean;
customHeaders?: { [key: string]: unknown };
http2SessionOptions?: Http2SessionOptions;
};

type Path = {
Expand Down Expand Up @@ -104,6 +108,7 @@ export class Authorizer {
baseUrl: serviceUrl,
interceptors: interceptors,
nodeOptions: baseNodeOptions,
...config?.http2SessionOptions,
});

this.AuthClient = createClient(AuthorizerClient, baseGrpcTransport);
Expand Down
9 changes: 7 additions & 2 deletions src/directory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,15 @@ export class Directory {
const nodeOptions = createNodeOptions(config);
let customHeaders = Object.assign({}, fallback?.customHeaders || {});
customHeaders = Object.assign(customHeaders, config?.customHeaders || {});
const http2SessionOptions =
config?.http2SessionOptions || fallback?.http2SessionOptions;

if (
serviceUrl !== baseServiceUrl ||
apiKey !== baseApiKey ||
tenantId !== baseTenantId ||
nodeOptions !== baseNodeOptions
nodeOptions !== baseNodeOptions ||
http2SessionOptions !== baseHttp2SessionOptions
) {
const interceptors = [createHeadersInterceptor(apiKey, tenantId)];
if (process.env.NODE_TRACE_MESSAGE) {
Expand All @@ -222,6 +225,7 @@ export class Directory {
baseUrl: serviceUrl || "https://localhost:9292",
interceptors: interceptors,
nodeOptions: nodeOptions,
...http2SessionOptions,
});
}
return baseGrpcTransport;
Expand All @@ -241,9 +245,9 @@ export class Directory {
}

const baseServiceUrl = config.url;

const baseApiKey = config.apiKey;
const baseTenantId = config.tenantId;
const baseHttp2SessionOptions = config.http2SessionOptions;
const baseCaFile = !!config.caFile
? readFileSync(config.caFile)
: undefined;
Expand All @@ -263,6 +267,7 @@ export class Directory {
baseUrl: baseServiceUrl || "https://localhost:9292",
interceptors: interceptors,
nodeOptions: baseNodeOptions,
...baseHttp2SessionOptions,
})
: undefined;

Expand Down
2 changes: 2 additions & 0 deletions src/directory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
Registry,
} from "@bufbuild/protobuf";
import { Timestamp } from "@bufbuild/protobuf/wkt";
import { Http2SessionOptions } from "@connectrpc/connect-node";

import { NestedOmit, NestedOptional, Optional } from "../util/types";

Expand Down Expand Up @@ -276,6 +277,7 @@ export type ServiceConfig = {
caFile?: string;
insecure?: boolean;
customHeaders?: CustomHeaders;
http2SessionOptions?: Http2SessionOptions;
};
export type SetManifestResponse = Omit<
SetManifestResponse$,
Expand Down
31 changes: 29 additions & 2 deletions tests/directory/v3/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DeleteObjectResponseSchema,
DeleteRelationResponseSchema,
Directory,
DirectoryConfig,
EtagMismatchError,
ExportResponseSchema,
GetGraphResponseSchema,
Expand Down Expand Up @@ -48,6 +49,7 @@ describe("Directory", () => {
customHeaders: {
foo: "bar",
},
idleConnectionTimeoutMs: 60000,
};
const directory = new Directory(config);

Expand All @@ -67,14 +69,17 @@ describe("Directory", () => {
return path as string;
});

const config = {
const config: DirectoryConfig = {
url: "https://localhost:9292",
tenantId: "tenantId",
apiKey: "apiKey",
caFile: "caFile",
customHeaders: {
base: "bar",
},
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
reader: {
url: "https://readerUrl",
apiKey: "readerApiKey",
Expand All @@ -83,6 +88,9 @@ describe("Directory", () => {
customHeaders: {
reader: "bar",
},
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
},
writer: {
url: "https://writerUrl",
Expand All @@ -91,21 +99,33 @@ describe("Directory", () => {
customHeaders: {
writer: "bar",
},
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
},
importer: {
url: "https://importerUrl",
apiKey: "importerApiKey",
tenantId: "importerTenantId",
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
},
exporter: {
caFile: "exporterCaFile",
customHeaders: {},
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
},
model: {
apiKey: "modelApiKey",
tenantId: "modelTenantId",
http2SessionOptions: {
idleConnectionTimeoutMs: 60000,
},
},
rejectUnauthorized: true,
insecure: false,
};

const directory = new Directory(config);
Expand All @@ -119,6 +139,7 @@ describe("Directory", () => {
ca: "caFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
[
Expand All @@ -129,6 +150,7 @@ describe("Directory", () => {
ca: "readerCaFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
[
Expand All @@ -139,6 +161,7 @@ describe("Directory", () => {
ca: "caFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
[
Expand All @@ -149,6 +172,7 @@ describe("Directory", () => {
ca: "caFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
[
Expand All @@ -159,6 +183,7 @@ describe("Directory", () => {
ca: "exporterCaFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
[
Expand All @@ -169,6 +194,7 @@ describe("Directory", () => {
ca: "caFile",
rejectUnauthorized: true,
},
idleConnectionTimeoutMs: 60000,
}),
],
]);
Expand All @@ -189,6 +215,7 @@ describe("Directory", () => {
url: "localhost:9292",
tenantId: "tenantId",
apiKey: "apiKey",
idleConnectionTimeoutMs: 60000,
reader: {
url: "readerUrl",
apiKey: "readerApiKey",
Expand Down