Skip to content

Commit

Permalink
feat(Inso): Add proxy settings to inso cli (#8257)
Browse files Browse the repository at this point in the history
* Use environment variables to set proxy settings on inso

* move proxy settings to cli commands

* cleanup

* proxyEnabled settings
  • Loading branch information
gatzjames authored Dec 20, 2024
1 parent c907e60 commit ab38dab
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions packages/insomnia-inso/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@ export const go = (args?: string[]) => {
const program = new commander.Command();
const version = process.env.VERSION || packageJson.version;

const proxySettings: {
proxyEnabled: boolean;
httpProxy: string;
httpsProxy: string;
noProxy: string;
} = {
proxyEnabled: false,
httpProxy: '',
httpsProxy: '',
noProxy: '',
};

if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
proxySettings.proxyEnabled = true;
proxySettings.httpProxy = process.env.HTTP_PROXY || '';
proxySettings.httpsProxy = process.env.HTTPS_PROXY || '';
proxySettings.noProxy = process.env.NO_PROXY || '';
}

// export and lint logic
// Provide a path to a file which looks like an insomnia db
// it may contain multiple workspaces, and specs.
Expand Down Expand Up @@ -354,7 +373,10 @@ export const go = (args?: string[]) => {
.option('-b, --bail', 'abort ("bail") after first test failure', false)
.option('--keepFile', 'do not delete the generated test file', false)
.option('-k, --disableCertValidation', 'disable certificate validation for requests with SSL', false)
.action(async (identifier, cmd: { env: string; testNamePattern: string; reporter: TestReporter; bail: boolean; keepFile: boolean; disableCertValidation: boolean; ci: boolean }) => {
.option('--httpsProxy <proxy>', 'proxy server for https requests', proxySettings.httpsProxy)
.option('--httpProxy <proxy>', 'proxy server for http requests', proxySettings.httpProxy)
.option('--noProxy <proxy>', 'proxy server for no proxy requests', proxySettings.noProxy)
.action(async (identifier, cmd: { env: string; testNamePattern: string; reporter: TestReporter; bail: boolean; keepFile: boolean; disableCertValidation: boolean; ci: boolean; httpsProxy?: string; httpProxy?: string; noProxy?: string }) => {
const globals: GlobalOptions = program.optsWithGlobals();
const commandOptions = { ...globals, ...cmd };
const __configFile = await tryToReadInsoConfigFile(commandOptions.config, commandOptions.workingDir);
Expand Down Expand Up @@ -413,8 +435,20 @@ export const go = (args?: string[]) => {
data: {},
};

const proxyOptions: {
proxyEnabled: boolean;
httpProxy?: string;
httpsProxy?: string;
noProxy?: string;
} = {
proxyEnabled: Boolean(options.httpProxy || options.httpsProxy),
httpProxy: options.httpProxy,
httpsProxy: options.httpsProxy,
noProxy: options.noProxy,
};

try {
const sendRequest = await getSendRequestCallbackMemDb(environment._id, db, transientVariables, { validateSSL: !options.disableCertValidation });
const sendRequest = await getSendRequestCallbackMemDb(environment._id, db, transientVariables, { validateSSL: !options.disableCertValidation, ...proxyOptions });
// Generate test file
const testFileContents = generate(suites.map(suite => ({
name: suite.name,
Expand Down Expand Up @@ -454,7 +488,10 @@ export const go = (args?: string[]) => {
.option('-r, --reporter <reporter>', `reporter to use, options are [${reporterTypes.join(', ')}]`, defaultReporter)
.option('-b, --bail', 'abort ("bail") after first non-200 response', false)
.option('--disableCertValidation', 'disable certificate validation for requests with SSL', false)
.action(async (identifier, cmd: { env: string; globals: string; disableCertValidation: boolean; requestNamePattern: string; bail: boolean; item: string[]; delayRequest: string; iterationCount: string; iterationData: string; envVar: string[] }) => {
.option('--httpsProxy <proxy>', 'proxy server for https requests', proxySettings.httpsProxy)
.option('--httpProxy <proxy>', 'proxy server for http requests', proxySettings.httpProxy)
.option('--noProxy <proxy>', 'proxy server for no proxy requests', proxySettings.noProxy)
.action(async (identifier, cmd: { env: string; globals: string; disableCertValidation: boolean; requestNamePattern: string; bail: boolean; item: string[]; delayRequest: string; iterationCount: string; iterationData: string; envVar: string[]; httpsProxy?: string; httpProxy?: string; noProxy?: string }) => {
const globals: { config: string; workingDir: string; exportFile: string; ci: boolean; printOptions: boolean; verbose: boolean } = program.optsWithGlobals();

const commandOptions = { ...globals, ...cmd };
Expand Down Expand Up @@ -603,7 +640,20 @@ export const go = (args?: string[]) => {
name: 'Transient Variables',
data: {},
};
const sendRequest = await getSendRequestCallbackMemDb(environment._id, db, transientVariables, { validateSSL: !options.disableCertValidation }, iterationData, iterationCount);

const proxyOptions: {
proxyEnabled: boolean;
httpProxy?: string;
httpsProxy?: string;
noProxy?: string;
} = {
proxyEnabled: Boolean(options.httpProxy || options.httpsProxy),
httpProxy: options.httpProxy,
httpsProxy: options.httpsProxy,
noProxy: options.noProxy,
};

const sendRequest = await getSendRequestCallbackMemDb(environment._id, db, transientVariables, { validateSSL: !options.disableCertValidation, ...proxyOptions }, iterationData, iterationCount);
let success = true;
for (let i = 0; i < iterationCount; i++) {
let reqIndex = 0;
Expand Down

0 comments on commit ab38dab

Please sign in to comment.