Skip to content

Commit

Permalink
SchemaRegistry: Add http agent argument
Browse files Browse the repository at this point in the history
Add option to pass in HTTP agent that binds to mappersmith
  • Loading branch information
seriouslag committed Apr 6, 2021
1 parent f8a4c5d commit de7f49e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/SchemaRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 19 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -19,6 +20,8 @@ export interface SchemaRegistryAPIClientArgs {
auth?: Authorization
clientId?: string
retry?: Partial<RetryMiddlewareOptions>
/** HTTP Agent that will be passed to underlying API calls */
agent?: Agent
}

// TODO: Improve typings
Expand All @@ -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,
Expand Down Expand Up @@ -100,3 +115,4 @@ export default ({
},
},
})
}

0 comments on commit de7f49e

Please sign in to comment.