@usebruno/cli
Version:
With Bruno CLI, you can now run your API collections with ease using simple command line commands.
45 lines (37 loc) • 1.11 kB
JavaScript
const { forOwn, cloneDeep } = require('lodash');
const { interpolate } = require('@usebruno/common');
const interpolateString = (str, { envVars, runtimeVariables, processEnvVars, externalSecretVariables }) => {
if (!str || !str.length || typeof str !== 'string') {
return str;
}
processEnvVars = processEnvVars || {};
runtimeVariables = runtimeVariables || {};
// 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
}
}
});
});
// runtimeVariables take precedence over envVars
const combinedVars = {
...envVars,
...runtimeVariables,
process: {
env: {
...processEnvVars
}
},
...externalSecretVariables
};
return interpolate(str, combinedVars);
};
module.exports = {
interpolateString
};