UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g

32 lines 1.2 kB
import { Client, fetch } from 'undici'; export function createMtlsClient(parsedPathToFetch, mtlsCerts = {}) { const { clientCert, clientKey, caCert } = mtlsCerts; const baseUrl = new URL(parsedPathToFetch).origin; if (clientCert && clientKey) { return new Client(baseUrl, { connect: { key: Buffer.from(clientKey), cert: Buffer.from(clientCert), ...(caCert && { ca: Buffer.from(caCert) }), // Keeping this `false` to have the ability to call different servers in one Arazzo file // some of them might not require mTLS. rejectUnauthorized: false, }, }); } return undefined; } export function withMtlsClientIfNeeded(mtlsCerts = {}) { if (!mtlsCerts) { return fetch; } return function fetchWithMtls(input, init) { const url = typeof input === 'string' ? input : 'url' in input ? input.url : input.toString(); const client = createMtlsClient(url, mtlsCerts); return fetch(input, { ...init, dispatcher: client, }); }; } //# sourceMappingURL=create-mtls-client.js.map