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

Rework error handling and state flow in the Azure connection #5356

Merged
merged 11 commits into from
Apr 17, 2020

Conversation

DHowett-MSFT
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT commented Apr 14, 2020

38429b5 - az: rework tenant/tenant storage and fix display names

Instead of passing around four loose variables, create a Tenant class
and use that for packing/unpacking into/out of json (and the windows
credential store, where we "cleverly" used json for the tenant info
there too).

When displaying a tenant, use its display name if there is one, the
unknown resource string if there isn't, and the default domain if there
is one and the ID if there isn't.

Fixes #5325.

9f6ebcb - az: use {fmt} for formatting request bodies

8a54e09 - az: remove dead strings

8985c38 - az: rework Request/HeaderHelper to Send(Authenticated?)ReqReturningJson

7ad9e88 - az: rewrite polling to use std::chrono

69b59cb - az: remove HR returns from state machine

2fe5f66 - az: rename state handlers from _XHelper to _RunXState

a1de8c3 - az: cleanup, prefix user input with >, remove namespaces

b5e16c2 - az: show more tenant info

Switch to 2020 tenant API; use defaultDomain; put defaultDomain into the
display name.

Consider: not showing the tenant GUID at all?

61f06e7 - az: rework error handling

  • _RequestHelper no longer eats exceptions.
  • Delete the "no internet" error message.
  • Wrap exceptions coming out of Azure API in a well-known type.
  • Catch by type.
  • Extract error codes for known failures (keep polling, invalid grant).
  • When we get an Invalid Grant, dispose of the cached refresh token and force the user to log in again.
  • Catch all printable exceptions and print them.
  • Remove the NoConnect state completely -- just bail out when an exception hits the toplevel of the output thread.
  • Move 3x logic into _RefreshTokens and pop exceptions out of it.
  • Begin abstracting into AzureClient

Summary of the Pull Request

This is a tidying-up of the azure connection. It improves error logging (like: it actually emits error logs...) and retry logic and the state machine and it audits the exit points of the state machine for exceptions and removes the HRESULT returns (so they either succeed and transition to a new state or throw an exception or are going down anyway).

There's also a change in here that changes how we display tenants. It adds the "default domain" to the name, so that instead of seeing this:

Conhost (aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
Default Directory (bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb)

you see this

Conhost (conhost.onmicrosoft.com)
Default Directory (dustinhowett.onmicrosoft.com)

References

Fixes #5325 (by addressing its chief complaint).
Fixes #4803.
Adds diagnosability for #4575.

PR Checklist

Detailed Description of the Pull Request / Additional comments

As above.

Validation Steps Performed

Logged in, out, around a good number of times.

@DHowett-MSFT
Copy link
Contributor Author

nts: we can remove AzureExitStr as well.

DHowett added 7 commits April 14, 2020 15:27
* _RequestHelper no longer eats exceptions.
* Delete the "no internet" error message.
* Wrap exceptions coming out of Azure API in a well-known type.
* Catch by type.
* Extract error codes for known failures (keep polling, invalid grant).
* When we get an Invalid Grant, dispose of the cached refresh token and force the user to log in again.
* Catch all printable exceptions and print them.
* Remove the NoConnect state completely -- just bail out when an exception hits the toplevel of the output thread.
* Move 3x logic into _RefreshTokens and pop exceptions out of it.
* Begin abstracting into AzureClient
Switch to 2020 tenant API; use defaultDomain; put defaultDomain into the
display name.

Consider: not showing the tenant GUID at all?
@DHowett-MSFT DHowett-MSFT force-pushed the dev/duhowett/azure-3 branch from 89b9de6 to 2417105 Compare April 14, 2020 22:28
@DHowett-MSFT
Copy link
Contributor Author

Confirmed this actually fixes #4803, doesn’t just improve diagnostics.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I think I'm fine with this. If we want, we can pull the FQDN without impacting too much else of this PR, right?

{
try
{
throw;
Copy link
Member

Choose a reason for hiding this comment

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

what the heck

does this just get the current exception if you're already in a catch block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

YES it’s great

@zadjii-msft zadjii-msft added Area-AzureShell Workitems pertaining to the Azure Cloud Shell connection. Product-Terminal The new Windows Terminal. labels Apr 15, 2020
@zadjii-msft zadjii-msft added this to the Terminal v1.x milestone Apr 15, 2020
@DHowett-MSFT
Copy link
Contributor Author

Yeah def

@DHowett-MSFT
Copy link
Contributor Author

Alright, got to this:
image

default domain if available, ID otherwise, and this supports loading up old version credentials

DHowett added 2 commits April 15, 2020 12:49
Instead of passing around four loose variables, create a Tenant class
and use that for packing/unpacking into/out of json (and the windows
credential store, where we "cleverly" used json for the tenant info
there too).

When displaying a tenant, use its display name if there is one, the
unknown resource string if there isn't, and the default domain if there
is one and the ID if there isn't.

Fixes #5325.
@DHowett-MSFT DHowett-MSFT force-pushed the dev/duhowett/azure-3 branch from 2417105 to 38429b5 Compare April 15, 2020 20:00
@DHowett-MSFT DHowett-MSFT marked this pull request as ready for review April 15, 2020 20:04
@DHowett-MSFT DHowett-MSFT merged commit c186c7d into master Apr 17, 2020
@DHowett-MSFT DHowett-MSFT deleted the dev/duhowett/azure-3 branch April 17, 2020 00:32
@ghost
Copy link

ghost commented Apr 22, 2020

🎉Windows Terminal Preview v0.11.1121.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AzureShell Workitems pertaining to the Azure Cloud Shell connection. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to Rename / Name Tenants Azure Shell can't connect to the internet
4 participants