Skip to content

Commit

Permalink
Merge pull request #108 from seriouslag/feature/schemaRegistry/add-ht…
Browse files Browse the repository at this point in the history
…tp-agent-arg

SchemaRegistry: Add http agent argument
  • Loading branch information
Nevon authored Apr 14, 2021
2 parents b40e4d4 + 3942728 commit 10d38ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 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: 18 additions & 4 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, Options } 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,10 @@ export default ({
clientId,
host,
retry = {},
}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient =>
forge({
agent,
}: SchemaRegistryAPIClientArgs): SchemaRegistryAPIClient => {
// FIXME: ResourcesType typings is not exposed by mappersmith
const manifest: Options<any> = {
clientId: clientId || DEFAULT_API_CLIENT_ID,
ignoreGlobalMiddleware: true,
host,
Expand Down Expand Up @@ -99,4 +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)
}

0 comments on commit 10d38ff

Please sign in to comment.