Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement proxy usage #11

Merged
merged 4 commits into from
Feb 1, 2022

Conversation

BlackDark
Copy link
Contributor

@BlackDark BlackDark commented Aug 18, 2021

Closes #10

Have written small changes for proxy usage.
Tested in my environment where i need a proxy.

Released necessary package and adapted changes to the github action:

Tried using it in an action

      - name: Setup terraform
        uses: BlackDark/setup-terraform@proxy-custom-pkg
        with:
          terraform_version: ^1.0.0

Works:

image

@hashicorp-cla
Copy link

hashicorp-cla commented Aug 18, 2021

CLA assistant check
All committers have signed the CLA.

@bahag-welscha
Copy link

What is the progress of this PR? I faced the same issue that the binaries can't be downloaded when a proxy is used.
With the Fork from @BlackDark i have no problem to download the binaries with active proxy.

@duxbuse
Copy link

duxbuse commented Nov 15, 2021

+1 please merge this

@jpogran
Copy link
Contributor

jpogran commented Nov 18, 2021

Hi @BlackDark, apologies for the delay in response. Thank you for the contribution! This looks like a good addition but there are a few things to get sorted first.

We had to update openpgp to latest stable in another PR, but that has made conflicting changes for you. Can you please rebase on main and fold those in?

It's hard to tell what changes are necessary to get proxy support added when you're reformatted the entire file. Can you please walk back the formatting changes so we can review this PR?

@BlackDark BlackDark force-pushed the feat/proxy-implementation branch from 47db578 to 472f491 Compare November 19, 2021 08:07
@BlackDark BlackDark force-pushed the feat/proxy-implementation branch from 472f491 to 3d16347 Compare November 19, 2021 08:11
@BlackDark
Copy link
Contributor Author

Hi @BlackDark, apologies for the delay in response. Thank you for the contribution! This looks like a good addition but there are a few things to get sorted first.

We had to update openpgp to latest stable in another PR, but that has made conflicting changes for you. Can you please rebase on main and fold those in?

It's hard to tell what changes are necessary to get proxy support added when you're reformatted the entire file. Can you please walk back the formatting changes so we can review this PR?

@jpogran Rebased and cleanup up commit

Copy link
Contributor

@jpogran jpogran left a comment

Choose a reason for hiding this comment

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

Minor request not to print proxy details to the console. Going to look into how this library is handling errors versus the presentation here.

src/utils.ts Outdated
Comment on lines 10 to 12
console.log(`Found proxy setting. Using to download files.`);
console.log(`HTTP: ${httpProxy}`);
console.log(`HTTPS: ${httpProxy}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(`Found proxy setting. Using to download files.`);
console.log(`HTTP: ${httpProxy}`);
console.log(`HTTPS: ${httpProxy}`);

We shouldn't be printing to the console proxy details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

src/utils.ts Outdated
url: string,
options: AxiosRequestConfig = {}
): Promise<any> {
console.log(`Request to: ${url} with options: ${JSON.stringify(options)}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(`Request to: ${url} with options: ${JSON.stringify(options)}`);

We shouldn't be printing to the console proxy details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would be the best solution to add debug functionality to check if the correct proxy is used?
The default set up job (on Github Enterprise) also prints proxy configs if setup:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good question, and is something that has some variance in implementations. In this case we expect the application using this library to output information like this, not the library itself.

Logging information is an important task of any library, but there isn't a way in this library to currently log anything. A future PR could introduce an interface and method overload that allows logging to different targets, but this is out of scope here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

src/utils.ts Outdated
Comment on lines 31 to 32
console.error(e.toJSON());
throw new Error(`Request for terraform binary failed: ${e && e.message}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Going to ask internally about the usage for this library, but I think we should follow the previous pattern of the resolve/reject with promises instead of try/catch and printing a message to the console.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reviewed with the team and we agree the approach here is good with the exception of catching the error here. We shouldn't print the error to the console and throw a new formatted here.

This library is used for more than downloading terraform, so instead we should let the caller handle the exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove the try catch so the caller must handle the error

@jpogran
Copy link
Contributor

jpogran commented Nov 19, 2021

Looking good so far. If you could add a short note to the README about the environment variables needed in order to activate this functionality I'd appreciate it. If not I can do that as a follow up.

@BlackDark
Copy link
Contributor Author

Looking good so far. If you could add a short note to the README about the environment variables needed in order to activate this functionality I'd appreciate it. If not I can do that as a follow up.

Hi @jpogran found some time working on my PR. Updated your comments as suggested and updated the README.

@dbanck
Copy link
Member

dbanck commented Dec 10, 2021

Thanks a lot for the updates.

I noticed one thing when running npm install.

found 8 vulnerabilities (6 moderate, 1 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

Most of the vulnerabilities are related to dev packages and not part of this PR, but the critical one is. It was introduced by a dependency of proxy-agent and can be fixed by running npm update vm2 --depth 5.

Do you mind updating the deps accordingly?

@BlackDark
Copy link
Contributor Author

npm update vm2 --depth 5

Updated the dependency :)

Copy link
Contributor

@jpogran jpogran left a comment

Choose a reason for hiding this comment

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

Thank you for contributing this!

@jpogran
Copy link
Contributor

jpogran commented Feb 1, 2022

Apologies on the delay, merging this now!

@jpogran jpogran merged commit 71512e5 into hashicorp:main Feb 1, 2022
@dbanck dbanck mentioned this pull request Mar 14, 2022
@magnetikonline
Copy link
Contributor

Hey @BlackDark / @jpogran - I've been tracking an annoying deprecation warning I've been seeing in the https://github.com/hashicorp/setup-terraform GitHub Action recently.

(node:1617) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

This is actually seen in the opening screenshot 😄.

Tracking this back, it's been this change that's cause the message:

Got there!

I wonder if there is an alternative to the proxy-agent package?

@jpogran
Copy link
Contributor

jpogran commented Apr 29, 2022

@magnetikonline I've created a new issue for request with the content you've posted. We'll look into seeing what can be done about this..

Next time, you can open a new issue and link to the PR in question instead of posting to a closed PR. Not all projects keep tabs on closed PRs.

@magnetikonline
Copy link
Contributor

Next time, you can open a new issue and link to the PR in question instead of posting to a closed PR. Not all projects keep tabs on closed PRs.

Fair call @jpogran - sorry about that.

@BlackDark BlackDark deleted the feat/proxy-implementation branch August 22, 2022 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Proxy settings
7 participants