Merge pull request #603 from keycloakify/debug_fetch_proxy
Debug fetch proxy
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "10.0.0-rc.128",
|
"version": "10.0.0-rc.131",
|
||||||
"description": "Create Keycloak themes using React",
|
"description": "Create Keycloak themes using React",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { type FetchOptions } from "make-fetch-happen";
|
import { type FetchOptions } from "make-fetch-happen";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import { exclude } from "tsafe/exclude";
|
||||||
|
|
||||||
export type ProxyFetchOptions = Pick<
|
export type ProxyFetchOptions = Pick<
|
||||||
FetchOptions,
|
FetchOptions,
|
||||||
@ -23,12 +24,32 @@ export function getProxyFetchOptions(params: {
|
|||||||
.split("\n")
|
.split("\n")
|
||||||
.filter(line => !line.startsWith(";"))
|
.filter(line => !line.startsWith(";"))
|
||||||
.map(line => line.trim())
|
.map(line => line.trim())
|
||||||
.map(line => line.split("=", 2) as [string, string])
|
.map(line => {
|
||||||
|
const [key, value] = line.split("=");
|
||||||
|
if (key === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return [key.trim(), value.trim()] as const;
|
||||||
|
})
|
||||||
|
.filter(exclude(undefined))
|
||||||
|
.filter(([key]) => key !== "")
|
||||||
|
.map(([key, value]) => {
|
||||||
|
if (value.startsWith('"') && value.endsWith('"')) {
|
||||||
|
return [key, value.slice(1, -1)] as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value === "true" || value === "false") {
|
||||||
|
return [key, value] as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
})
|
||||||
|
.filter(exclude(undefined))
|
||||||
.reduce(
|
.reduce(
|
||||||
(
|
(cfg: Record<string, string | string[]>, [key, value]) =>
|
||||||
cfg: Record<string, string | string[]>,
|
|
||||||
[key, value]: [string, string]
|
|
||||||
) =>
|
|
||||||
key in cfg
|
key in cfg
|
||||||
? { ...cfg, [key]: [...ensureArray(cfg[key]), value] }
|
? { ...cfg, [key]: [...ensureArray(cfg[key]), value] }
|
||||||
: { ...cfg, [key]: value },
|
: { ...cfg, [key]: value },
|
||||||
@ -37,18 +58,18 @@ export function getProxyFetchOptions(params: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
|
const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
|
||||||
|
|
||||||
const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
|
const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
|
||||||
|
|
||||||
function maybeBoolean(arg0: string | undefined) {
|
const strictSSL = ensureSingleOrNone(cfg["strict-ssl"]) === "true";
|
||||||
return typeof arg0 === "undefined" ? undefined : Boolean(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"]));
|
|
||||||
const cert = cfg["cert"];
|
const cert = cfg["cert"];
|
||||||
|
|
||||||
const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]);
|
const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]);
|
||||||
|
|
||||||
const cafile = ensureSingleOrNone(cfg["cafile"]);
|
const cafile = ensureSingleOrNone(cfg["cafile"]);
|
||||||
|
|
||||||
if (typeof cafile !== "undefined" && cafile !== "null") {
|
if (cafile !== undefined) {
|
||||||
ca.push(
|
ca.push(
|
||||||
...(() => {
|
...(() => {
|
||||||
const cafileContent = fs.readFileSync(cafile).toString("utf8");
|
const cafileContent = fs.readFileSync(cafile).toString("utf8");
|
||||||
@ -82,7 +103,7 @@ export function getProxyFetchOptions(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensureArray<T>(arg0: T | T[]) {
|
function ensureArray<T>(arg0: T | T[]) {
|
||||||
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
return Array.isArray(arg0) ? arg0 : arg0 === undefined ? [] : [arg0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
||||||
|
Reference in New Issue
Block a user