@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
45 lines (44 loc) • 1.59 kB
JavaScript
import https from "https";
import { HttpsProxyAgent } from "https-proxy-agent";
import { DEFAULT_TLS_VERSION, OPTION_TLS_VERSION } from "../../constants.js";
import { get } from "../../logger/index.js";
import { getOptionValueFromConfig } from "../options.js";
const getLogger = () => get("http");
export const getTlsVersion = () => {
return getOptionValueFromConfig(OPTION_TLS_VERSION, DEFAULT_TLS_VERSION);
};
export const isLegacyTlsDetectionEnabled = () => {
return process.env.CLI_LEGACY_TLS_DETECTION === "true";
};
export const createTlsAgentOptions = () => {
const { debug } = getLogger();
if (isLegacyTlsDetectionEnabled()) {
debug("using legacy TLS detection - letting Node.js decide default TLS version");
return {
rejectUnauthorized: true,
};
}
const tlsVersion = getTlsVersion();
debug(`configuring HTTPS agent with TLS version: ${tlsVersion}`);
const agentOptions = {
minVersion: tlsVersion,
maxVersion: tlsVersion,
rejectUnauthorized: true,
};
debug("HTTPS agent options:", JSON.stringify(agentOptions, null, 2));
return agentOptions;
};
export const createHttpsAgent = (proxy) => {
const { debug } = getLogger();
const agentOptions = createTlsAgentOptions();
let agent;
if (proxy) {
agent = new HttpsProxyAgent(proxy, agentOptions);
debug(`created HttpsProxyAgent with proxy: ${proxy}`);
}
else {
agent = new https.Agent(agentOptions);
debug("created https.Agent with TLS configuration");
}
return agent;
};