Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

allow truffle compile behind corporate proxy Issue 4016 #5847

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/compile-solidity/package.json
Expand Up @@ -28,6 +28,7 @@
"axios-retry": "^3.1.9",
"debug": "^4.3.1",
"fs-extra": "^9.1.0",
"https-proxy-agent": "^5.0.0",
"iter-tools": "^7.0.2",
"lodash": "^4.17.21",
"node-abort-controller": "^3.0.1",
Expand Down
Expand Up @@ -6,7 +6,19 @@ import originalRequire from "original-require";

// must polyfill AbortController to use axios >=0.20.0, <=0.27.2 on node <= v14.x
import "../../polyfill";
import { default as axios, AxiosResponse } from "axios";
import { default as axiosPlain, AxiosResponse } from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const environmentProxy = process.env.https_proxy || process.env.http_proxy;
let axios;
if (environmentProxy) {
const agent = new HttpsProxyAgent(environmentProxy);
axios = axiosPlain.create({
httpsAgent: agent
});
} else {
axios = axiosPlain;
}
Comment on lines +19 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the most recent rebase undid initializing axios to axiosPlain

Copy link
Author

@joseluu joseluu Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will be able to test with the next release incorporating the updated axios.

However I couldn't make the "plain test" below work with axios 1.2.5
activating the embedded proxy code in axios 1.2.5 either by environment vars or
by explicit code led to "handshakefailed" errors from the McAfee proxy I am behind
----------- plain test --------

const axios = require('axios');
axios.get('https://api.ipify.org/?format=json')
    .then(res => {
        console.log(res.data)
    }).catch(err => console.error(err))

---------- proxied test using axios ------------

const axios = require('axios');
 
const req = axios({
  url: 'https://api.ipify.org/?format=json',
  proxy: {
    host: 'proxy-host',
    port: 8080,
    auth: {
      username: ‘the-user’,
      password: ‘his-password’,
    },
  },
});

---------- proxied test using the https-proxy-agent module

const axios_plain = require('axios');
var proxy = process.env.https_proxy || process.env.http_proxy;
var axios;
if (proxy) {
    const HttpsProxyAgent = require('https-proxy-agent');
     console.log('using proxy server %j', proxy);
    const agent = new HttpsProxyAgent(proxy)
    axios=axios_plain.create( {
    httpsAgent: agent
        });
} else {
    axios = axios_plain;
}
axios.get('https://api.ipify.org/?format=json',)
    .then(res => {
        console.log(res.data)
    }).catch(err => console.error(err))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @joseluu, did the latest release resolve your proxy issue? I don't have an easy way to test this :/ I wonder if it's related to this TunnelAgent.httpsOverHttp comment in a related Axios issue. 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the v5.7.4 does not solve the issue (see screenshot)
The TunnelAgent comment is another but similar way of explicitly adding an httpsAgent when creating the connection. This solution uses the package tunnel-agent rather than https-proxy-agent.

truffle_V5 7 4_proxy_test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joseluu! Bummer the dep upgrade didn't resolve the issue. You mentioned there were problems with axios 1.2.4 above, can you confirm your PR still works for your configuration?

This issue has been dogging us for a while, and I'd like to document the various proxy configurations, so we can incorporate proxy testing in CI. Would you be able to describe your setup? Thanks again!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased the patch on v5.7.4, and checked operation behind a firewall: it works


import semver from "semver";

Expand Down Expand Up @@ -186,7 +198,7 @@ export class VersionRange {
return this.compilerFromString(response.data);
}

async getSolcFromCacheOrUrl(versionConstraint: string, index: number = 0) {
async getSolcFromCacheOrUrl(versionConstraint: string, index = 0) {
// go through all sources (compilerRoots) trying to locate a
// suitable version of the Solidity compiler
const { compilerRoots, events } = this.config;
Expand Down Expand Up @@ -257,7 +269,7 @@ export class VersionRange {
version.includes("nightly") || version.includes("commit");

if (isPrerelease) {
for (let build of allVersions.builds) {
for (const build of allVersions.builds) {
const exists =
build["prerelease"] === version ||
build["build"] === version ||
Expand Down