mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-15 20:01:28 +00:00
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
const { forOwn, cloneDeep } = require('lodash');
|
|
const { interpolate } = require('@usebruno/common');
|
|
|
|
const interpolateString = (str, { envVars, collectionVariables, processEnvVars }) => {
|
|
if (!str || !str.length || typeof str !== 'string') {
|
|
return str;
|
|
}
|
|
|
|
processEnvVars = processEnvVars || {};
|
|
collectionVariables = collectionVariables || {};
|
|
|
|
// we clone envVars because we don't want to modify the original object
|
|
envVars = envVars ? cloneDeep(envVars) : {};
|
|
|
|
// envVars can inturn have values as {{process.env.VAR_NAME}}
|
|
// so we need to interpolate envVars first with processEnvVars
|
|
forOwn(envVars, (value, key) => {
|
|
envVars[key] = interpolate(value, {
|
|
process: {
|
|
env: {
|
|
...processEnvVars
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// collectionVariables take precedence over envVars
|
|
const combinedVars = {
|
|
...envVars,
|
|
...collectionVariables,
|
|
process: {
|
|
env: {
|
|
...processEnvVars
|
|
}
|
|
}
|
|
};
|
|
|
|
return interpolate(str, combinedVars);
|
|
};
|
|
|
|
module.exports = {
|
|
interpolateString
|
|
};
|