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

Handle Gateway links #289

Merged
merged 14 commits into from
Aug 18, 2023
Merged

Handle Gateway links #289

merged 14 commits into from
Aug 18, 2023

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Aug 7, 2023

I created a new class to share some common connection code between the step-based wizard flow and the link-based flow. I think we can share more things as we go on but I did not try too hard to combine more code until the shape of the link-based flow solidifies some more. So there is some duplication like the authentication loop, logging in the CLI, etc, that cannot be easily shared without some refactoring.

It might even end up being that we just always launch into the wizard flow but if some parameters are already set we automatically skip through certain steps. Not sure.

This is a first pass, right now you have to specify most of the parameters yourself (aside from deployment URL and token which, if missing, will trigger prompts to the user).

There are a few todos that I want to take in subsequent PRs to make the experience better, like making sure the workspace is on (and turning it on if needed) and giving the ability to select the IDE you want if one was not specified (or perhaps defaulting to the last used one).

The flow can be triggered with a URL like this:

jetbrains-gateway://connect#type=coder&workspace=dev&agent=coder&folder=/home/coder&url=https://oss.demo.coder.com&token=<redacted>&ide_product_code=IU&ide_build_number=223.8836.41&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2022.3.3.tar.gz

For example, this should work if you run gateway.sh <url>. But this build of the plugin will need to be already installed since otherwise it will automatically install the currently published version which does not support the link yet.

Or, if running Gateway from the runIDE task (which will build and provide the plugin automatically), pass the URL via --args.

Or, something like xdg-open <url> (on Linux) might work too.

Or, adding it as an external link to a template.

More details in the commit messages, and they can be reviewed separately.

Closes #149.

The connect entrypoint is used both for Gateway
links (jetbrains-gateway://) and internally in our own code at the end
of the wizard and for recent connections, but this will be two separate
sets of parameters (internally we have the CLI set up and pass around
the hostname while the links will only have the workspace ID or name).

So break out the code into a separate class that we can call internally
which will let us dedicate the connect entrypoint to handle the Gateway
links.  There we will set up the CLI and gather the required parameters
before calling the now-broken-out code.
So it can be reused in the link flow.
When you connect via a Gateway link it might not be obvious if the
deployment URL is wrong.
Some exceptions have no message, like null pointer exceptions.  Showing
the class name seems more helpful than "no details", since it can save
you a trip to the logs.
@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

Qodana Community for JVM

53 new problems were found

Inspection name Severity Problems
Unused symbol 🔶 Warning 32
Unstable API Usage 🔶 Warning 8
Incorrect string capitalization 🔶 Warning 7
Call to 'equals()' or 'hashCode()' on 'URL' object 🔶 Warning 2
Local 'var' is never modified and can be declared as 'val' 🔶 Warning 1
Redundant semicolon 🔶 Warning 1
Useless call on not-null type 🔶 Warning 1
Trailing comma recommendations ◽️ Notice 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

  1. Register at Qodana Cloud and configure the action
  2. Use GitHub Code Scanning with Qodana
  3. Host Qodana report at GitHub Pages
  4. Inspect and use qodana.sarif.json (see the Qodana SARIF format for details)

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2023.2.1
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

Rather than asking the user to confirm.  This only happens if we
explicitly want to use an existing token anyway, and "existing" is
defined in the help text as either the token on disk or one the user
already copied, so the extra confirmation to use the token on disk seems
unnecessary.
Also add a few checks against the status.
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

👍

Comment on lines +257 to +263
is SSLHandshakeException ->
throw Exception(CoderGatewayBundle.message(
"gateway.connector.view.workspaces.connect.ssl-error",
url.host,
e.message ?: CoderGatewayBundle.message("gateway.connector.view.workspaces.connect.no-reason")
))
else -> throw e
Copy link
Member

Choose a reason for hiding this comment

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

This may cause some headaches if the required certs are not available in the JRE keystore. I think it should be fine if it's trusted by the system though.

Copy link
Member Author

Choose a reason for hiding this comment

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

From my testing (although I might have missed something), adding to the system trust store was not enough, it had to be in the JRE key store that was bundled with Gateway.

The help text has a link to the docs that explains how to add the cert, but I do think it would be nice as a future enhancement to give the option to view and accept the cert. Not sure how difficult that would be.

The deployment host is probably not exactly where the IDEs would be
stored if self-serving.  Probably at most they would share a root
domain.  For now remove it, we can add it back or something like it back
if we figure out some usage patterns, although making it configurable is
probably the better bet anyway.
@code-asher code-asher merged commit a7e08c2 into main Aug 18, 2023
6 checks passed
@code-asher code-asher deleted the asher/gateway-link branch August 18, 2023 17:14
@matifali
Copy link

related to coder/coder#9679

@bpmct bpmct mentioned this pull request Sep 18, 2023
2 tasks
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.

One-click experience to Gateway from Coder dashboard
3 participants