mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-05 13:39:13 +01:00
feat(#224): Bru CLI support for proxying requests
This commit is contained in:
parent
3661fa7df3
commit
f695036721
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.10.0
|
||||||
|
|
||||||
|
- Support for proxying requests through a proxy server
|
||||||
|
|
||||||
## 0.9.0
|
## 0.9.0
|
||||||
|
|
||||||
- `--output` flag to collect the results of your API tests
|
- `--output` flag to collect the results of your API tests
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@usebruno/cli",
|
"name": "@usebruno/cli",
|
||||||
"version": "0.9.0",
|
"version": "0.10.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -165,6 +165,9 @@ const handler = async function (argv) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const brunoConfigFile = fs.readFileSync(brunoJsonPath, 'utf8');
|
||||||
|
const brunoConfig = JSON.parse(brunoConfigFile);
|
||||||
|
|
||||||
if (filename && filename.length) {
|
if (filename && filename.length) {
|
||||||
const pathExists = await exists(filename);
|
const pathExists = await exists(filename);
|
||||||
if (!pathExists) {
|
if (!pathExists) {
|
||||||
@ -304,7 +307,8 @@ const handler = async function (argv) {
|
|||||||
collectionPath,
|
collectionPath,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
envVars,
|
envVars,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
brunoConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -85,6 +85,17 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces
|
|||||||
param.value = interpolate(param.value);
|
param.value = interpolate(param.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (request.proxy) {
|
||||||
|
request.proxy.protocol = interpolate(request.proxy.protocol);
|
||||||
|
request.proxy.hostname = interpolate(request.proxy.hostname);
|
||||||
|
request.proxy.port = interpolate(request.proxy.port);
|
||||||
|
|
||||||
|
if (request.proxy.auth) {
|
||||||
|
request.proxy.auth.username = interpolate(request.proxy.auth.username);
|
||||||
|
request.proxy.auth.password = interpolate(request.proxy.auth.password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ const runSingleRequest = async function (
|
|||||||
collectionPath,
|
collectionPath,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
envVariables,
|
envVariables,
|
||||||
processEnvVars
|
processEnvVars,
|
||||||
|
brunoConfig
|
||||||
) {
|
) {
|
||||||
let request;
|
let request;
|
||||||
|
|
||||||
@ -39,7 +40,14 @@ const runSingleRequest = async function (
|
|||||||
const preRequestVars = get(bruJson, 'request.vars.req');
|
const preRequestVars = get(bruJson, 'request.vars.req');
|
||||||
if (preRequestVars && preRequestVars.length) {
|
if (preRequestVars && preRequestVars.length) {
|
||||||
const varsRuntime = new VarsRuntime();
|
const varsRuntime = new VarsRuntime();
|
||||||
varsRuntime.runPreRequestVars(preRequestVars, request, envVariables, collectionVariables, collectionPath);
|
varsRuntime.runPreRequestVars(
|
||||||
|
preRequestVars,
|
||||||
|
request,
|
||||||
|
envVariables,
|
||||||
|
collectionVariables,
|
||||||
|
collectionPath,
|
||||||
|
processEnvVars
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run pre request script
|
// run pre request script
|
||||||
@ -51,10 +59,37 @@ const runSingleRequest = async function (
|
|||||||
request,
|
request,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
null,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set proxy if enabled
|
||||||
|
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
|
||||||
|
if (proxyEnabled) {
|
||||||
|
const proxyProtocol = get(brunoConfig, 'proxy.protocol');
|
||||||
|
const proxyHostname = get(brunoConfig, 'proxy.hostname');
|
||||||
|
const proxyPort = get(brunoConfig, 'proxy.port');
|
||||||
|
const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false);
|
||||||
|
|
||||||
|
const proxyConfig = {
|
||||||
|
protocol: proxyProtocol,
|
||||||
|
hostname: proxyHostname,
|
||||||
|
port: proxyPort
|
||||||
|
};
|
||||||
|
if (proxyAuthEnabled) {
|
||||||
|
const proxyAuthUsername = get(brunoConfig, 'proxy.auth.username');
|
||||||
|
const proxyAuthPassword = get(brunoConfig, 'proxy.auth.password');
|
||||||
|
proxyConfig.auth = {
|
||||||
|
username: proxyAuthUsername,
|
||||||
|
password: proxyAuthPassword
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
request.proxy = proxyConfig;
|
||||||
|
}
|
||||||
|
|
||||||
// interpolate variables inside request
|
// interpolate variables inside request
|
||||||
interpolateVars(request, envVariables, collectionVariables, processEnvVars);
|
interpolateVars(request, envVariables, collectionVariables, processEnvVars);
|
||||||
|
|
||||||
@ -102,7 +137,8 @@ const runSingleRequest = async function (
|
|||||||
response,
|
response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +152,9 @@ const runSingleRequest = async function (
|
|||||||
response,
|
response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
null,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +193,9 @@ const runSingleRequest = async function (
|
|||||||
response,
|
response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
null,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
testResults = get(result, 'results', []);
|
testResults = get(result, 'results', []);
|
||||||
}
|
}
|
||||||
@ -202,7 +242,8 @@ const runSingleRequest = async function (
|
|||||||
err.response,
|
err.response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +257,9 @@ const runSingleRequest = async function (
|
|||||||
err.response,
|
err.response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
null,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +298,9 @@ const runSingleRequest = async function (
|
|||||||
err.response,
|
err.response,
|
||||||
envVariables,
|
envVariables,
|
||||||
collectionVariables,
|
collectionVariables,
|
||||||
collectionPath
|
collectionPath,
|
||||||
|
null,
|
||||||
|
processEnvVars
|
||||||
);
|
);
|
||||||
testResults = get(result, 'results', []);
|
testResults = get(result, 'results', []);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user