mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
Merge pull request #183 from BrentShikoski/feature/support-custom-cacert
support alternative cacert file in cli
This commit is contained in:
commit
4c25aa99aa
@ -113,6 +113,10 @@ const builder = async (yargs) => {
|
||||
type: 'boolean',
|
||||
default: false
|
||||
})
|
||||
.option('cacert', {
|
||||
type: 'string',
|
||||
description: 'CA certificate to verify peer against'
|
||||
})
|
||||
.option('env', {
|
||||
describe: 'Environment variables',
|
||||
type: 'string',
|
||||
@ -131,6 +135,7 @@ const handler = async function (argv) {
|
||||
try {
|
||||
let {
|
||||
filename,
|
||||
cacert,
|
||||
env,
|
||||
insecure,
|
||||
r: recursive
|
||||
@ -178,7 +183,21 @@ const handler = async function (argv) {
|
||||
const options = getOptions();
|
||||
if(insecure) {
|
||||
options['insecure'] = true
|
||||
}
|
||||
}
|
||||
if(cacert && cacert.length) {
|
||||
if(insecure) {
|
||||
console.error(chalk.red(`Ignoring the cacert option since insecure connections are enabled`));
|
||||
}
|
||||
else {
|
||||
const pathExists = await exists(cacert);
|
||||
if(pathExists) {
|
||||
options['cacert'] = cacert
|
||||
}
|
||||
else {
|
||||
console.error(chalk.red(`Cacert File ${cacert} does not exist`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const _isFile = await isFile(filename);
|
||||
if(_isFile) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
const qs = require('qs');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const { forOwn, each, extend, get } = require('lodash');
|
||||
const FormData = require('form-data');
|
||||
const axios = require('axios');
|
||||
@ -44,12 +45,26 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll
|
||||
// interpolate variables inside request
|
||||
interpolateVars(request, envVariables, collectionVariables);
|
||||
|
||||
const insecure = get(getOptions(), 'insecure', false);
|
||||
const options = getOptions();
|
||||
const insecure = get(options, 'insecure', false);
|
||||
if(insecure) {
|
||||
request.httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
}
|
||||
else {
|
||||
const cacert = options['cacert'];
|
||||
if (cacert && cacert.length > 1) {
|
||||
try {
|
||||
caCrt = fs.readFileSync(cacert)
|
||||
request.httpsAgent = new https.Agent({
|
||||
ca: caCrt
|
||||
});
|
||||
} catch(err) {
|
||||
console.log('Error reading CA cert file:' + cacert, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stringify the request url encoded params
|
||||
if(request.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
|
Loading…
Reference in New Issue
Block a user