mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix: Pass PROXY in child Process (#4013)
This commit is contained in:
parent
7be12083d0
commit
aaa80f8055
9 changed files with 75 additions and 58 deletions
|
@ -1,6 +1,7 @@
|
||||||
const { exec } = require('child-process-promise');
|
const { exec } = require('child-process-promise');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const upath = require('upath');
|
const upath = require('upath');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
const { getPkgReleases } = require('../../datasource/docker');
|
const { getPkgReleases } = require('../../datasource/docker');
|
||||||
const {
|
const {
|
||||||
|
@ -40,13 +41,7 @@ async function updateArtifacts(
|
||||||
const localPackageFileName = upath.join(config.localDir, packageFileName);
|
const localPackageFileName = upath.join(config.localDir, packageFileName);
|
||||||
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
||||||
const localLockFileName = upath.join(config.localDir, lockFileName);
|
const localLockFileName = upath.join(config.localDir, lockFileName);
|
||||||
const env =
|
const env = getChildProcessEnv();
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
};
|
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
let cmd;
|
let cmd;
|
||||||
if (config.binarySource === 'docker') {
|
if (config.binarySource === 'docker') {
|
||||||
|
|
|
@ -2,6 +2,7 @@ const upath = require('upath');
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { exec } = require('child-process-promise');
|
const { exec } = require('child-process-promise');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateArtifacts,
|
updateArtifacts,
|
||||||
|
@ -32,13 +33,7 @@ async function updateArtifacts(
|
||||||
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
||||||
logger.debug('Updating ' + lockFileName);
|
logger.debug('Updating ' + lockFileName);
|
||||||
const cwd = config.localDir;
|
const cwd = config.localDir;
|
||||||
const env =
|
const env = getChildProcessEnv();
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
};
|
|
||||||
for (let i = 0; i < updatedDeps.length; i += 1) {
|
for (let i = 0; i < updatedDeps.length; i += 1) {
|
||||||
const dep = updatedDeps[i];
|
const dep = updatedDeps[i];
|
||||||
// Update dependency `${dep}` in Cargo.lock file corresponding to Cargo.toml file located
|
// Update dependency `${dep}` in Cargo.lock file corresponding to Cargo.toml file located
|
||||||
|
|
|
@ -4,6 +4,7 @@ const { exec } = require('child-process-promise');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const upath = require('upath');
|
const upath = require('upath');
|
||||||
const hostRules = require('../../util/host-rules');
|
const hostRules = require('../../util/host-rules');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateArtifacts,
|
updateArtifacts,
|
||||||
|
@ -95,14 +96,7 @@ async function updateArtifacts(
|
||||||
const localAuthFileName = upath.join(cwd, 'auth.json');
|
const localAuthFileName = upath.join(cwd, 'auth.json');
|
||||||
await fs.outputFile(localAuthFileName, JSON.stringify(authJson));
|
await fs.outputFile(localAuthFileName, JSON.stringify(authJson));
|
||||||
}
|
}
|
||||||
const env =
|
const env = getChildProcessEnv(['COMPOSER_CACHE_DIR']);
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
COMPOSER_CACHE_DIR: process.env.COMPOSER_CACHE_DIR,
|
|
||||||
};
|
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
let cmd;
|
let cmd;
|
||||||
if (config.binarySource === 'docker') {
|
if (config.binarySource === 'docker') {
|
||||||
|
|
|
@ -2,6 +2,7 @@ const { exec } = require('child-process-promise');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const upath = require('upath');
|
const upath = require('upath');
|
||||||
const hostRules = require('../../util/host-rules');
|
const hostRules = require('../../util/host-rules');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateArtifacts,
|
updateArtifacts,
|
||||||
|
@ -38,14 +39,7 @@ async function updateArtifacts(
|
||||||
}
|
}
|
||||||
await fs.outputFile(localGoModFileName, massagedGoMod);
|
await fs.outputFile(localGoModFileName, massagedGoMod);
|
||||||
const localGoSumFileName = upath.join(config.localDir, sumFileName);
|
const localGoSumFileName = upath.join(config.localDir, sumFileName);
|
||||||
const env =
|
const env = getChildProcessEnv(['GOPATH']);
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
GOPATH: process.env.GOPATH,
|
|
||||||
};
|
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
let cmd;
|
let cmd;
|
||||||
if (config.binarySource === 'docker') {
|
if (config.binarySource === 'docker') {
|
||||||
|
|
|
@ -8,6 +8,7 @@ const lerna = require('./lerna');
|
||||||
const yarn = require('./yarn');
|
const yarn = require('./yarn');
|
||||||
const pnpm = require('./pnpm');
|
const pnpm = require('./pnpm');
|
||||||
const hostRules = require('../../../util/host-rules');
|
const hostRules = require('../../../util/host-rules');
|
||||||
|
const { getChildProcessEnv } = require('../../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
determineLockFileDirs,
|
determineLockFileDirs,
|
||||||
|
@ -365,17 +366,11 @@ async function getAdditionalFiles(config, packageFiles) {
|
||||||
process.env.npm_config_store ||
|
process.env.npm_config_store ||
|
||||||
upath.join(config.cacheDir, './others/pnpm');
|
upath.join(config.cacheDir, './others/pnpm');
|
||||||
await fs.ensureDir(process.env.npm_config_store);
|
await fs.ensureDir(process.env.npm_config_store);
|
||||||
|
const env = getChildProcessEnv([
|
||||||
const env =
|
'NPM_CONFIG_CACHE',
|
||||||
global.trustLevel === 'high'
|
'YARN_CACHE_FOLDER',
|
||||||
? process.env
|
'npm_config_store',
|
||||||
: {
|
]);
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
NPM_CONFIG_CACHE: process.env.NPM_CONFIG_CACHE,
|
|
||||||
YARN_CACHE_FOLDER: process.env.YARN_CACHE_FOLDER,
|
|
||||||
npm_config_store: process.env.npm_config_store,
|
|
||||||
};
|
|
||||||
env.NODE_ENV = 'dev';
|
env.NODE_ENV = 'dev';
|
||||||
|
|
||||||
let token = '';
|
let token = '';
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const { exec } = require('child-process-promise');
|
const { exec } = require('child-process-promise');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const upath = require('upath');
|
const upath = require('upath');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateArtifacts,
|
updateArtifacts,
|
||||||
|
@ -31,16 +32,7 @@ async function updateArtifacts(
|
||||||
const localPipfileFileName = upath.join(config.localDir, pipfileName);
|
const localPipfileFileName = upath.join(config.localDir, pipfileName);
|
||||||
await fs.outputFile(localPipfileFileName, newPipfileContent);
|
await fs.outputFile(localPipfileFileName, newPipfileContent);
|
||||||
const localLockFileName = upath.join(config.localDir, lockFileName);
|
const localLockFileName = upath.join(config.localDir, lockFileName);
|
||||||
const env =
|
const env = getChildProcessEnv(['LC_ALL', 'LANG', 'PIPENV_CACHE_DIR']);
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
LC_ALL: process.env.LC_ALL,
|
|
||||||
LANG: process.env.LANG,
|
|
||||||
PIPENV_CACHE_DIR: process.env.PIPENV_CACHE_DIR,
|
|
||||||
};
|
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
let cmd;
|
let cmd;
|
||||||
if (config.binarySource === 'docker') {
|
if (config.binarySource === 'docker') {
|
||||||
|
|
|
@ -2,6 +2,7 @@ const upath = require('upath');
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { exec } = require('child-process-promise');
|
const { exec } = require('child-process-promise');
|
||||||
|
const { getChildProcessEnv } = require('../../util/env');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateArtifacts,
|
updateArtifacts,
|
||||||
|
@ -42,13 +43,7 @@ async function updateArtifacts(
|
||||||
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
await fs.outputFile(localPackageFileName, newPackageFileContent);
|
||||||
logger.debug(`Updating ${lockFileName}`);
|
logger.debug(`Updating ${lockFileName}`);
|
||||||
const cwd = upath.join(config.localDir, subDirectory);
|
const cwd = upath.join(config.localDir, subDirectory);
|
||||||
const env =
|
const env = getChildProcessEnv();
|
||||||
global.trustLevel === 'high'
|
|
||||||
? process.env
|
|
||||||
: {
|
|
||||||
HOME: process.env.HOME,
|
|
||||||
PATH: process.env.PATH,
|
|
||||||
};
|
|
||||||
let cmd;
|
let cmd;
|
||||||
// istanbul ignore if
|
// istanbul ignore if
|
||||||
if (config.binarySource === 'docker') {
|
if (config.binarySource === 'docker') {
|
||||||
|
|
24
lib/util/env.js
Normal file
24
lib/util/env.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
function getChildProcessEnv(customEnvVars = []) {
|
||||||
|
const env = {};
|
||||||
|
if (global.trustLevel === 'high') {
|
||||||
|
return Object.assign(env, process.env);
|
||||||
|
}
|
||||||
|
const envVars = [
|
||||||
|
'HTTP_PROXY',
|
||||||
|
'HTTPS_PROXY',
|
||||||
|
'NO_PROXY',
|
||||||
|
'HOME',
|
||||||
|
'PATH',
|
||||||
|
...customEnvVars,
|
||||||
|
];
|
||||||
|
envVars.forEach(envVar => {
|
||||||
|
if (typeof process.env[envVar] !== 'undefined') {
|
||||||
|
env[envVar] = process.env[envVar];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getChildProcessEnv,
|
||||||
|
};
|
33
test/util/env.spec.js
Normal file
33
test/util/env.spec.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
const { getChildProcessEnv } = require('../../lib/util/env');
|
||||||
|
|
||||||
|
describe('getChildProcess environment when trustlevel set to low', () => {
|
||||||
|
const envVars = ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'HOME', 'PATH'];
|
||||||
|
beforeEach(() => {
|
||||||
|
envVars.forEach(env => {
|
||||||
|
process.env[env] = env;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
envVars.forEach(env => delete process.env[env]);
|
||||||
|
});
|
||||||
|
it('returns default environment variables', () => {
|
||||||
|
expect(getChildProcessEnv()).toHaveProperty(...envVars);
|
||||||
|
});
|
||||||
|
it('returns environment variable only if defined', () => {
|
||||||
|
delete process.env.PATH;
|
||||||
|
expect(getChildProcessEnv()).not.toHaveProperty('PATH');
|
||||||
|
});
|
||||||
|
it('returns custom environment variables if passed and defined', () => {
|
||||||
|
process.env.LANG = 'LANG';
|
||||||
|
expect(getChildProcessEnv(['LANG'])).toHaveProperty(...envVars, 'LANG');
|
||||||
|
delete process.env.LANG;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getChildProcessEnv when trustlevel set to high', () => {
|
||||||
|
it('returns process.env if trustlevel set to high', () => {
|
||||||
|
global.trustLevel = 'high';
|
||||||
|
expect(getChildProcessEnv()).toMatchObject(process.env);
|
||||||
|
delete global.trustLevel;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue