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

Parse deep links sent to Connect #33639

Merged
merged 4 commits into from Oct 20, 2023
Merged

Conversation

ravicious
Copy link
Member

@ravicious ravicious commented Oct 18, 2023

This PR builds on top of #33637. After receiving an URL, we want to parse it and pass the result of it to the frontend app. This PR implements just the parsing.

This PR doesn't show it, but we generally want to send the whole parsing result to the frontend app. This way in case of any problems the frontend app can show a relevant notification rather than just doing nothing. For example, imagine in v15 we add support for another deep link. If someone with v14 clicks on it, we should display some kind of an error instead of just doing nothing. This will be done in a subsequent PR but I just wanted to explain the structure of the code in this PR.

I had to install whatwg-url to parse URLs. That's because the implementation varies wildly between different implementations, especially when using custom protocols. Since uri.ts can be potentially used both on the Node.js side as well as the Chromium side, I wanted to play it safe.

Different kinds of URIs

One thing which I had hard time navigating is that what we call URIs in uri.ts are Connect's identifiers for various things, e.g. a specific SSH server on a specific leaf cluster or a specific tab in the app etc. Those identifiers take the form of just the path of an actual URI, e.g. /clusters/foo.cloud.gravitational.io/dbs/postgres-prod.

This PRs adds support for search params to some of those URIs. In case of the Connect My Computer deep link, we want to be able to pass the username so that if the user is not logged in already, we can prefill the login form.

So this notion of a URI is somehow different than what is considered a URI (or rather a URL) when dealing with deep links. The actual deep link URLs will follow the format of teleport:// + Connect's internal URI format, so for example teleport:///clusters/foo.cloud.gravitational.io/connect_my_computer. The format is totally up to us, as long as it's understood as valid by browsers.

I chose this format because the format of the path follows the format already established by Connect. Since it's the first time we need to use some kind of a word separator in our URIs, I chose the underscore as the word separator. This is because we already use the underscore for resource kids and those resource kinds are used in ResourceIDs. If we were ever to coalesce ResourceIDs with our URIs, I guess it's best to keep the word separator the same.


Here's a fiddle with deep links you can use for testing. Remember that this will only work if you installed a packaged app.

@ravicious ravicious removed the request for review from ibeckermayer October 18, 2023 15:00
@ravicious ravicious force-pushed the ravicious/deep-link-2-main-process branch 2 times, most recently from 3d7d727 to 25b459d Compare October 18, 2023 15:14
@ravicious
Copy link
Member Author

Omg, I completely missed the fact that the import of whatwg-url in uri.ts impacts any other test which imports uri.ts (and thus whatwg-url).

I'll have to come up with a better solution than selectively changing jest-environment through a top level comment.

See:

@ibeckermayer
Copy link
Contributor

Omg, I completely missed the fact that the import of whatwg-url in uri.ts impacts any other test which imports uri.ts (and thus whatwg-url).

I'll have to come up with a better solution than selectively changing jest-environment through a top level comment.

See:

I'v only glanced at this so I'm not sure if this is relevant, but since you linked to jsdom's lack of TextEncoder in relation to tests, this might be useful to you:

// This is needed for tests until jsdom adds support for TextEncoder (https://github.com/jsdom/jsdom/issues/2524)
window.TextEncoder = window.TextEncoder || TestTextEncoder;
window.TextDecoder = window.TextDecoder || TestTextDecoder;

@ravicious
Copy link
Member Author

ravicious commented Oct 19, 2023

@ibeckermayer Thanks for the tip, I didn't bother to check if we're already dealing with this problem in our codebase!

I believe the issue is on the part of Jest, not jsdom (see jsdom/jsdom#2524 (comment)). I couldn't find a good fix though so for now I'm probably going to use the same approach.

Edit: Addressed that in #33683.

@ravicious ravicious force-pushed the ravicious/deep-link-2-main-process branch from 25b459d to 28f7530 Compare October 19, 2023 10:02
Base automatically changed from ravicious/deep-link-1-setup to master October 19, 2023 11:18
@ravicious ravicious force-pushed the ravicious/deep-link-2-main-process branch from 28f7530 to d568d54 Compare October 19, 2023 11:26
@ravicious ravicious changed the base branch from master to ravicious/jest-jsdom October 19, 2023 11:27
Copy link
Contributor

@gzdunek gzdunek left a comment

Choose a reason for hiding this comment

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

I agree with the decision on links format.

Base automatically changed from ravicious/jest-jsdom to master October 20, 2023 10:15
`this` used within objects like this loses type information due to implicit
any used by TypeScript there. Instead, we can refer to `routing` (like
other functions already do) and keep type information.
@ravicious ravicious force-pushed the ravicious/deep-link-2-main-process branch from d568d54 to 97eb577 Compare October 20, 2023 10:43
@ravicious ravicious added this pull request to the merge queue Oct 20, 2023
Merged via the queue into master with commit 0af059a Oct 20, 2023
35 checks passed
@ravicious ravicious deleted the ravicious/deep-link-2-main-process branch October 20, 2023 11:02
@public-teleport-github-review-bot

@ravicious See the table below for backport results.

Branch Result
branch/v14 Create PR

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.

None yet

4 participants