From 27b0b8ab085d6a56749d11235fc04efd230ab33a Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Tue, 6 Apr 2021 10:11:36 -0400 Subject: [PATCH 1/4] SchemaRegistry: Add http agent argument Add option to pass in HTTP agent that binds to mappersmith --- src/SchemaRegistry.ts | 4 ++-- src/api/index.ts | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/SchemaRegistry.ts b/src/SchemaRegistry.ts index 6194557..3f31ffd 100644 --- a/src/SchemaRegistry.ts +++ b/src/SchemaRegistry.ts @@ -50,10 +50,10 @@ export default class SchemaRegistry { public cache: Cache constructor( - { auth, clientId, host, retry }: SchemaRegistryAPIClientArgs, + { auth, clientId, host, retry, agent }: SchemaRegistryAPIClientArgs, options?: SchemaRegistryAPIClientOptions, ) { - this.api = API({ auth, clientId, host, retry }) + this.api = API({ auth, clientId, host, retry, agent }) this.cache = new Cache() this.options = options } diff --git a/src/api/index.ts b/src/api/index.ts index 4c6d426..e877e64 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,5 @@ -import forge, { Client, Authorization } from 'mappersmith' +import { Agent } from 'http' +import forge, { Authorization, Client, configs } from 'mappersmith' import RetryMiddleware, { RetryMiddlewareOptions } from 'mappersmith/middleware/retry/v2' import BasicAuthMiddleware from 'mappersmith/middleware/basic-auth' @@ -19,6 +20,8 @@ export interface SchemaRegistryAPIClientArgs { auth?: Authorization clientId?: string retry?: Partial + /** HTTP Agent that will be passed to underlying API calls */ + agent?: Agent } // TODO: Improve typings @@ -43,8 +46,20 @@ export default ({ clientId, host, retry = {}, -}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => - forge({ + agent, +}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => { + // TODO: figure out how to only bind agent to host URL + // if an agent was provided, bind the agent to the mappersmith configs + if (agent) { + configs.gatewayConfigs.HTTP = { + configure() { + return { + agent, + } + }, + } + } + return forge({ clientId: clientId || DEFAULT_API_CLIENT_ID, ignoreGlobalMiddleware: true, host, @@ -100,3 +115,4 @@ export default ({ }, }, }) +} From 0f59e712d5d215b887666c0da7c09b749da23d7f Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Tue, 6 Apr 2021 10:11:36 -0400 Subject: [PATCH 2/4] SchemaRegistry: Add http agent argument Add option to pass in HTTP agent that binds to mappersmith --- src/SchemaRegistry.ts | 4 ++-- src/api/index.ts | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/SchemaRegistry.ts b/src/SchemaRegistry.ts index 6194557..3f31ffd 100644 --- a/src/SchemaRegistry.ts +++ b/src/SchemaRegistry.ts @@ -50,10 +50,10 @@ export default class SchemaRegistry { public cache: Cache constructor( - { auth, clientId, host, retry }: SchemaRegistryAPIClientArgs, + { auth, clientId, host, retry, agent }: SchemaRegistryAPIClientArgs, options?: SchemaRegistryAPIClientOptions, ) { - this.api = API({ auth, clientId, host, retry }) + this.api = API({ auth, clientId, host, retry, agent }) this.cache = new Cache() this.options = options } diff --git a/src/api/index.ts b/src/api/index.ts index 4c6d426..e877e64 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,5 @@ -import forge, { Client, Authorization } from 'mappersmith' +import { Agent } from 'http' +import forge, { Authorization, Client, configs } from 'mappersmith' import RetryMiddleware, { RetryMiddlewareOptions } from 'mappersmith/middleware/retry/v2' import BasicAuthMiddleware from 'mappersmith/middleware/basic-auth' @@ -19,6 +20,8 @@ export interface SchemaRegistryAPIClientArgs { auth?: Authorization clientId?: string retry?: Partial + /** HTTP Agent that will be passed to underlying API calls */ + agent?: Agent } // TODO: Improve typings @@ -43,8 +46,20 @@ export default ({ clientId, host, retry = {}, -}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => - forge({ + agent, +}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => { + // TODO: figure out how to only bind agent to host URL + // if an agent was provided, bind the agent to the mappersmith configs + if (agent) { + configs.gatewayConfigs.HTTP = { + configure() { + return { + agent, + } + }, + } + } + return forge({ clientId: clientId || DEFAULT_API_CLIENT_ID, ignoreGlobalMiddleware: true, host, @@ -100,3 +115,4 @@ export default ({ }, }, }) +} From d78272fe30c85b1a6173a82b2fbf7e3253ce45ae Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Tue, 13 Apr 2021 19:08:25 -0400 Subject: [PATCH 3/4] SchemaRegistry: Remove binding agent to global --- src/api/index.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index e877e64..9cfbca6 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,5 +1,5 @@ import { Agent } from 'http' -import forge, { Authorization, Client, configs } from 'mappersmith' +import forge, { Authorization, Client, Options } from 'mappersmith' import RetryMiddleware, { RetryMiddlewareOptions } from 'mappersmith/middleware/retry/v2' import BasicAuthMiddleware from 'mappersmith/middleware/basic-auth' @@ -48,18 +48,8 @@ export default ({ retry = {}, agent, }: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => { - // TODO: figure out how to only bind agent to host URL - // if an agent was provided, bind the agent to the mappersmith configs - if (agent) { - configs.gatewayConfigs.HTTP = { - configure() { - return { - agent, - } - }, - } - } - return forge({ + // FIXME: ResourcesType typings is not exposed by mappersmith + const manifest: Options = { clientId: clientId || DEFAULT_API_CLIENT_ID, ignoreGlobalMiddleware: true, host, @@ -114,5 +104,13 @@ export default ({ }, }, }, - }) + } + // if an agent was provided, bind the agent to the mappersmith configs + if (agent) { + // gatewayConfigs is not listed as a type on manifest object in mappersmith + ;(manifest as any).gatewayConfigs = { + configure: () => agent, + } + } + return forge(manifest) } From 39427282897559edaf2a70554ba98e47e0139c16 Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Wed, 14 Apr 2021 10:19:05 -0400 Subject: [PATCH 4/4] SchemaRegistry: Fix return of config configure --- src/api/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/index.ts b/src/api/index.ts index 9cfbca6..4802411 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -109,7 +109,7 @@ export default ({ if (agent) { // gatewayConfigs is not listed as a type on manifest object in mappersmith ;(manifest as any).gatewayConfigs = { - configure: () => agent, + configure: () => ({ agent }), } } return forge(manifest)