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

Adds the ability to use a proxy, Closes #2698 #4679

Closed
wants to merge 17 commits into from

Conversation

nicodecleyre
Copy link
Contributor

Closes #2698

@milanholemans
Copy link
Contributor

Nice work, we'll review it ASAP!

src/request.ts Outdated Show resolved Hide resolved
Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Almost there! Let's do a couple more adjustments and clarify the use of ports vs. protocols.

docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
docs/docs/user-guide/using-proxy-url.md Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Almost there! Let's do a couple more adjustments and clarify the use of ports vs. protocols.

@waldekmastykarz waldekmastykarz marked this pull request as draft May 13, 2023 07:52
@nicodecleyre nicodecleyre marked this pull request as ready for review May 13, 2023 18:55
@nicodecleyre
Copy link
Contributor Author

Thank you for the review @waldekmastykarz, the PR is updated! Can you take another look?

@waldekmastykarz
Copy link
Member

Will do 👍

@Jwaegebaert Jwaegebaert marked this pull request as draft May 31, 2023 09:26
@nicodecleyre nicodecleyre marked this pull request as ready for review June 5, 2023 19:35
Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Hey @nicodecleyre, sorry for late reply. Following our discussion and like suggested here: #2698 (comment), let's align with the common convention for Node.js apps and use the standard environment variables HTTP_PROXY and HTTPS_PROXY instead of introducing our own setting. That will make it more consistent with other Node.js apps and make the CLI more intuitive to use for folks who use Node.js.

@nicodecleyre
Copy link
Contributor Author

Hey @nicodecleyre, sorry for late reply. Following our discussion and like suggested here: #2698 (comment), let's align with the common convention for Node.js apps and use the standard environment variables HTTP_PROXY and HTTPS_PROXY instead of introducing our own setting. That will make it more consistent with other Node.js apps and make the CLI more intuitive to use for folks who use Node.js.

Hey @waldekmastykarz, would be a nice change if we could use the environment variables. A couple of months ago I did some research on this but wasn't able to find how to get this working in all interfaces/environments. Do you know by any chance if there is a call for these environment variables across all interfaces/environments?

@waldekmastykarz
Copy link
Member

Not sure what you mean with "across all interfaces/environments". Could you please elaborate @nicodecleyre? Also, looking at the PR once again, I realized that we haven't added support for proxying application insights calls, which has its own proxy setup. We've changed how telemetry is run #5327 but haven't merged it yet, so let's so let's ensure that we include the necessary changes there as well when we process this PR.

@waldekmastykarz waldekmastykarz marked this pull request as draft August 13, 2023 07:54
@nicodecleyre
Copy link
Contributor Author

Not sure what you mean with "across all interfaces/environments". Could you please elaborate @nicodecleyre? Also, looking at the PR once again, I realized that we haven't added support for proxying application insights calls, which has its own proxy setup. We've changed how telemetry is run #5327 but haven't merged it yet, so let's so let's ensure that we include the necessary changes there as well when we process this PR.

Hi @waldekmastykarz, what I mean with "across all interfaces/environments" is how do we ensure that we can retrieve the value of these environment variables in:

  • cmd in Windows
  • PowerShell in Windows
  • terminal in mac

as per my knowledge, you can set a env var in cmd like this:
image
but when i try to get the same env var in PS, it's not present:
image

No offense intended, but you said here that setting environment variable differs per shell and you don't think we can do anything about it. So i'm having a bit of a feeling that we're having the same discussion again 😄

I've looked at the PR, but I don't quite understand what you mean with "support for proxying application insights calls", can you elaborate what you expect for this in this PR?

@waldekmastykarz
Copy link
Member

Check, so with "environments" you mean "shells", understood.

Hi @waldekmastykarz, what I mean with "across all interfaces/environments" is how do we ensure that we can retrieve the value of these environment variables in:

While setting environment variables differs per shell like we discussed, it shouldn't be relevant to us because we only care about reading their value, which should be standardized and available through process.env.YOUR_ENV_VAR in Node.js. So while each shell will come with its own way to set these variables, that goes outside of our scopes, because we care only about the fact whether a variable is set or not, and not how it's been set.

I've looked at the PR, but I don't quite understand what you mean with "support for proxying application insights calls", can you elaborate what you expect for this in this PR?

In CLI for Microsoft 365 we use Application Insights to track telemetry. Application Insights comes with its own instrumentation for proxy and this PR should pass the proxy configuration to Application Insights too. In its current state, if the user set a proxy on their machine, our telemetry collection would not work.

@nicodecleyre
Copy link
Contributor Author

Hi @waldekmastykarz, I've included the telemetry changes from the PR you provided. But it keeps failing on 3 tests, can i get some guidance on this please?

@waldekmastykarz
Copy link
Member

Sure thing! Let me have a look

src/appInsights.ts Outdated Show resolved Hide resolved
src/appInsights.ts Outdated Show resolved Hide resolved
src/telemetry.ts Outdated Show resolved Hide resolved
@waldekmastykarz
Copy link
Member

Hey @nicodecleyre, is your branch still up to date? I'm seeing some odd changes as a part of the PR that don't seem to be related and seem like something that might've been pulled in? Could you please double check before we continue the review? Thanks!

@nicodecleyre
Copy link
Contributor Author

Hey @nicodecleyre, is your branch still up to date? I'm seeing some odd changes as a part of the PR that don't seem to be related and seem like something that might've been pulled in? Could you please double check before we continue the review? Thanks!

Hi @waldekmastykarz, I took the telemetry changes from the pr #5327 which isn't merged yet, as you asked. But maybe I misunderstood what you were trying to say?

@waldekmastykarz
Copy link
Member

Ah sorry, right. That got me confused. I thought we've already merged #5327 which isn't the case. All good.

@waldekmastykarz
Copy link
Member

Hey @nicodecleyre, now that we've merged #5327, could you please do one final rebase so that we can review your proposed changes and get them in? Thanks again for your patience 😊

Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Hey @nicodecleyre, when I rebase your PR onto the latest main, I'm getting 2 test failing:

image

Could you please have a look at what's wrong? I confirmed that these tests only fail after rebasing your PR. If I get latest from main, all tests pass and I get 100% coverage.

@waldekmastykarz waldekmastykarz marked this pull request as draft December 24, 2023 08:54
@nicodecleyre
Copy link
Contributor Author

Hi @waldekmastykarz, rebase done ✅

@nicodecleyre nicodecleyre marked this pull request as ready for review December 27, 2023 15:18
Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Almost there. Let's do a few more adjustments before we merge it

src/request.spec.ts Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
@waldekmastykarz waldekmastykarz marked this pull request as draft January 3, 2024 12:08
@nicodecleyre nicodecleyre marked this pull request as ready for review January 3, 2024 17:18
Copy link
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Very nicely done with a few cosmetic changes I've added when merging the PR 👏

@@ -396,10 +396,14 @@ describe('Request', () => {
});

it('returns response of a successful GET request, with a proxy url', (done) => {
let outcome = false;
Copy link
Member

Choose a reason for hiding this comment

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

It would be clearer to name the variable after what it represents, eg. proxyConfigured

sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'http://proxy.contoso.com:8080' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
if (_options.proxy && _options.proxy.host === 'proxy.contoso.com' && _options.proxy.port === 8080 && _options.proxy.protocol === 'http') {
Copy link
Member

Choose a reason for hiding this comment

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

We can simplify this code by assigning the outcome of the comparison directly to the proxyConfigured variable without an if

sinon.stub(process, 'env').value({ 'HTTPS_PROXY': 'http://username:password@proxy.contoso.com:8080' });

sinon.stub(_request as any, 'req').callsFake((options) => {
_options = options as CliRequestOptions;
if (_options.proxy && _options.proxy.host === 'proxy.contoso.com'
&& _options.proxy.port === 8080
Copy link
Member

Choose a reason for hiding this comment

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

Let's put operators at the end of line for readability

@@ -14,6 +14,7 @@ const settingsNames = {
printErrorsAsPlainText: 'printErrorsAsPlainText',
prompt: 'prompt',
promptListPageSize: 'promptListPageSize',
proxyUrl: 'proxyUrl',
Copy link
Member

Choose a reason for hiding this comment

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

We should remove it since we're not using it

@waldekmastykarz
Copy link
Member

Merged manually. Thank you! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug report: M365 login from behind corp proxy = Error: could not resolve endpoints
5 participants