mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 22:48:06 +00:00
a9c8f7431f
This now covers everything that isn't `isObject` or `typeof x === 'number'`. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { isNonEmptyString, isUndefined } from '@sindresorhus/is';
|
|
import { createGlobalProxyAgent } from 'global-agent';
|
|
import { logger } from './logger/index.ts';
|
|
import { addSecretForSanitizing } from './util/sanitize.ts';
|
|
import { parseUrl } from './util/url.ts';
|
|
|
|
const envVars = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'];
|
|
const proxyEnvVarsWithCredentials = ['HTTP_PROXY', 'HTTPS_PROXY'];
|
|
|
|
let agent = false;
|
|
|
|
function sanitizeProxyCredentials(envVar: string): void {
|
|
const uri = parseUrl(process.env[envVar]);
|
|
if (uri?.password) {
|
|
addSecretForSanitizing(uri.password, 'global');
|
|
}
|
|
}
|
|
|
|
export function bootstrap(): void {
|
|
envVars.forEach((envVar) => {
|
|
/* v8 ignore next -- env is case-insensitive on windows */
|
|
if (
|
|
isUndefined(process.env[envVar]) &&
|
|
!isUndefined(process.env[envVar.toLowerCase()])
|
|
) {
|
|
process.env[envVar] = process.env[envVar.toLowerCase()];
|
|
}
|
|
|
|
if (process.env[envVar]) {
|
|
logger.debug(`Detected ${envVar} value in env`);
|
|
process.env[envVar.toLowerCase()] = process.env[envVar];
|
|
}
|
|
});
|
|
|
|
proxyEnvVarsWithCredentials.forEach(sanitizeProxyCredentials);
|
|
|
|
if (
|
|
isNonEmptyString(process.env.HTTP_PROXY) ||
|
|
isNonEmptyString(process.env.HTTPS_PROXY)
|
|
) {
|
|
createGlobalProxyAgent({
|
|
environmentVariableNamespace: '',
|
|
});
|
|
agent = true;
|
|
} else {
|
|
// for testing only, does not reset global agent
|
|
agent = false;
|
|
}
|
|
}
|
|
|
|
// will be used by our http layer later
|
|
export function hasProxy(): boolean {
|
|
return agent === true;
|
|
}
|