Skip to content

Commit ded84d6

Browse files
committed
impl: add support for matching agent by name
This PR adds support for matching workspace agent in the URI via the `agent_name` query param. The existing support for `agent_id` is dropped and replaced by the new param.
1 parent 1a2212b commit ded84d6

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
- support for basic authentication for HTTP/HTTPS proxy
88
- support for Toolbox 2.7 release
9+
- support for matching workspace agent in the URI via the agent name
910

1011
### Changed
1112

1213
- improved message while loading the workspace
1314

15+
### Removed
16+
17+
- dropped support for `agent_id` as a URI parameter
18+
1419
### Fixed
1520

1621
- URI protocol handler is now able to switch to the Coder provider even if the last opened provider was something else

README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ You can use specially crafted JetBrains Gateway URIs to automatically:
6464
### Example URIs
6565

6666
```text
67-
jetbrains://gateway/com.coder.toolbox?url=https%3A%2F%2Fdev.coder.com&token=zeoX4SbSpP-j2qGpajkdwxR9jBdcekXS2&workspace=bobiverse-bob&agent=dev&ide_product_code=GO&ide_build_number=241.23774.119&folder=%2Fhome%2Fcoder%2Fworkspace%2Fhello-world-rs
67+
jetbrains://gateway/com.coder.toolbox?url=https%3A%2F%2Fdev.coder.com&token=zeoX4SbSpP-j2qGpajkdwxR9jBdcekXS2&workspace=bobiverse-bob&agent_name=dev&ide_product_code=GO&ide_build_number=241.23774.119&folder=%2Fhome%2Fcoder%2Fworkspace%2Fhello-world-rs
6868
69-
jetbrains://gateway/com.coder.toolbox?url=https%3A%2F%2Fj5gj2r1so5nbi.pit-1.try.coder.app%2F&token=gqEirOoI1U-FfCQ6uj8iOLtybBIk99rr8&workspace=bobiverse-riker&agent=dev&ide_product_code=RR&ide_build_number=243.26053.17&folder=%2Fhome%2Fcoder%2Fworkspace%2Fhello-world-rs
69+
jetbrains://gateway/com.coder.toolbox?url=https%3A%2F%2Fj5gj2r1so5nbi.pit-1.try.coder.app%2F&token=gqEirOoI1U-FfCQ6uj8iOLtybBIk99rr8&workspace=bobiverse-riker&agent_name=dev&ide_product_code=RR&ide_build_number=243.26053.17&folder=%2Fhome%2Fcoder%2Fworkspace%2Fhello-world-rs
7070
```
7171

7272
### URI Breakdown
@@ -76,13 +76,15 @@ jetbrains://gateway/com.coder.toolbox
7676
?url=http(s)://<your-coder-deployment>
7777
&token=<auth-token>
7878
&workspace=<workspace-name>
79-
&agent_id=<agent--id>
79+
&agent_name=<agent-name>
8080
&ide_product_code=<IDE-code>
8181
&ide_build_number=<IDE-build>
8282
&folder=<absolute-path-to-a-project-folder>
8383
```
8484

85-
Starting from Toolbox 2.7, you can use `coder` as a shortcut in place of the full plugin ID. The URI can be simplified as:
85+
Starting from Toolbox 2.7, you can use `coder` as a shortcut in place of the full plugin ID. The URI can be simplified
86+
as:
87+
8688
```text
8789
jetbrains://gateway/coder?url=http(s)://<your-coder-deployment>
8890
```
@@ -92,16 +94,15 @@ jetbrains://gateway/coder?url=http(s)://<your-coder-deployment>
9294
| url | Your Coder deployment URL (encoded) | Yes |
9395
| token | Coder authentication token | Yes |
9496
| workspace | Name of the Coder workspace to connect to. | Yes |
95-
| agent_id | ID of the agent associated with the workspace | No |
97+
| agent_name | The name of the agent with the workspace | No |
9698
| ide_product_code | JetBrains IDE product code (e.g., GO for GoLand, RR for Rider) | No |
9799
| ide_build_number | Specific build number of the JetBrains IDE to install on the workspace | No |
98100
| folder | Absolute path to the project folder to open in the remote IDE (URL-encoded) | No |
99101

100102
> [!NOTE]
101-
> If only a single agent is available, specifying an agent ID is optional. However, if multiple agents exist,
102-
> you must provide either the ID to target a specific one. Note that this version of the Coder Toolbox plugin
103-
> does not automatically start agents if they are offline, so please ensure the selected agent is running before
104-
> proceeding.
103+
> If only a single agent is available, specifying an agent name. However, if multiple agents exist, you must provide the
104+
> agent name. Note that this version of the Coder Toolbox plugin does not automatically start agents if they
105+
> are offline, so please ensure the selected agent is running before proceeding.
105106
106107
If `ide_product_code` and `ide_build_number` is missing, Toolbox will only open and highlight the workspace environment
107108
page. Coder Toolbox will attempt to start the workspace if it’s not already running; however, for the most reliable
@@ -151,7 +152,9 @@ mitmweb --ssl-insecure --set stream_large_bodies="10m" --mode socks5
151152
> [!NOTE]
152153
> Coder Toolbox plugin handles only HTTP/HTTPS proxy authentication.
153154
> SOCKS5 proxy authentication is currently not supported due to limitations
154-
> described in: https://youtrack.jetbrains.com/issue/TBX-14532/Missing-proxy-authentication-settings#focus=Comments-27-12265861.0-0
155+
> described
156+
>
157+
in: https://youtrack.jetbrains.com/issue/TBX-14532/Missing-proxy-authentication-settings#focus=Comments-27-12265861.0-0
155158

156159
## Debugging and Reporting issues
157160

@@ -198,56 +201,56 @@ storage paths. The options can be configured from the plugin's main Workspaces p
198201
### CLI related settings
199202

200203
- `Binary source` specifies the source URL or relative path from which the Coder CLI should be downloaded.
201-
If a relative path is provided, it is resolved against the deployment domain.
204+
If a relative path is provided, it is resolved against the deployment domain.
202205

203206
- `Enable downloads` allows automatic downloading of the CLI if the current version is missing or outdated.
204207

205208
- `Binary directory` specifies the directory where CLI binaries are stored. If omitted, it defaults to the data
206-
directory.
209+
directory.
207210

208211
- `Enable binary directory fallback` if enabled, falls back to the data directory when the specified binary
209-
directory is not writable.
212+
directory is not writable.
210213

211214
- `Data directory` directory where plugin-specific data such as session tokens and binaries are stored if not
212-
overridden by the binary directory setting.
215+
overridden by the binary directory setting.
213216

214217
- `Header command` command that outputs additional HTTP headers. Each line of output must be in the format key=value.
215-
The environment variable CODER_URL will be available to the command process.
218+
The environment variable CODER_URL will be available to the command process.
216219

217220
### TLS settings
218221

219222
The following options control the secure communication behavior of the plugin with Coder deployment and its available
220223
API.
221224

222225
- `TLS cert path` path to a client certificate file for TLS authentication with Coder deployment.
223-
The certificate should be in X.509 PEM format.
226+
The certificate should be in X.509 PEM format.
224227

225228
- `TLS key path` path to the private key corresponding to the TLS certificate from above.
226-
The certificate should be in X.509 PEM format.
229+
The certificate should be in X.509 PEM format.
227230

228231
- `TLS CA path` the path of a file containing certificates for an alternate certificate authority used to verify TLS
229-
certs returned by the Coder deployment. The file should be in X.509 PEM format. This option can also be used to verify
230-
proxy certificates.
232+
certs returned by the Coder deployment. The file should be in X.509 PEM format. This option can also be used to verify
233+
proxy certificates.
231234

232235
- `TLS alternate hostname` overrides the hostname used in TLS verification. This is useful when the hostname
233-
used to connect to the Coder deployment does not match the hostname in the TLS certificate.
236+
used to connect to the Coder deployment does not match the hostname in the TLS certificate.
234237

235238
### SSH settings
236239

237240
The following options control the SSH behavior of the Coder CLI.
238241

239242
- `Disable autostart` adds the --disable-autostart flag to the SSH proxy command, preventing the CLI from keeping
240-
workspaces constantly active.
243+
workspaces constantly active.
241244

242245
- `Enable SSH wildcard config` enables or disables wildcard entries in the SSH configuration, which allow generic
243-
rules for matching multiple workspaces.
246+
rules for matching multiple workspaces.
244247

245248
- `SSH proxy log directory` directory where SSH proxy logs are written. Useful for debugging SSH connection issues.
246249

247250
- `SSH network metrics directory` directory where network information used by the SSH proxy is stored.
248251

249252
- `Extra SSH options` additional options appended to the SSH configuration. Can be used to customize the behavior of
250-
SSH connections.
253+
SSH connections.
251254

252255
### Saving Changes
253256

@@ -256,7 +259,7 @@ support, may trigger regeneration of SSH configurations.
256259

257260
### Security considerations
258261

259-
> [!IMPORTANT]
262+
> [!IMPORTANT]
260263
> Token authentication is required when TLS certificates are not configured.
261264
262265
## Releasing
@@ -269,6 +272,7 @@ support, may trigger regeneration of SSH configurations.
269272
JetBrains enabled auto-approval for the plugin, so we need to ensure we continue to meet the following requirements:
270273
- do **not** use Kotlin experimental APIs.
271274
- do **not** add any lambdas, handlers, or class handles to Java runtime hooks.
272-
- do **not** create threads manually (including via libraries). If you must, ensure they are properly cleaned up in the plugin's `CoderRemoteProvider#close()` method.
275+
- do **not** create threads manually (including via libraries). If you must, ensure they are properly cleaned up in
276+
the plugin's `CoderRemoteProvider#close()` method.
273277
- do **not** bundle libraries that are already provided by Toolbox.
274278
- do **not** perform any ill-intentioned actions.

src/main/kotlin/com/coder/toolbox/util/CoderProtocolHandler.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,25 @@ open class CoderProtocolHandler(
258258
}
259259

260260
// If the agent is missing and the workspace has only one, use that.
261-
val agent =
262-
if (!parameters.agentID().isNullOrBlank()) {
263-
agents.firstOrNull { it.id.toString() == parameters.agentID() }
264-
} else if (agents.size == 1) {
265-
agents.first()
266-
} else {
267-
null
268-
}
261+
val agent = if (!parameters.agentName().isNullOrBlank()) {
262+
agents.firstOrNull { it.name == parameters.agentName() }
263+
} else if (agents.size == 1) {
264+
agents.first()
265+
} else {
266+
null
267+
}
269268

270269
if (agent == null) {
271-
if (!parameters.agentID().isNullOrBlank()) {
270+
if (!parameters.agentName().isNullOrBlank()) {
272271
context.logAndShowError(
273272
CAN_T_HANDLE_URI_TITLE,
274-
"The workspace \"${workspace.name}\" does not have an agent with ID \"${parameters.agentID()}\""
273+
"The workspace \"${workspace.name}\" does not have an agent with name \"${parameters.agentName()}\""
275274
)
276275
return null
277276
} else {
278277
context.logAndShowError(
279278
CAN_T_HANDLE_URI_TITLE,
280-
"Unable to determine which agent to connect to; \"$AGENT_ID\" must be set because the workspace \"${workspace.name}\" has more than one agent"
279+
"Unable to determine which agent to connect to; \"$AGENT_NAME\" must be set because the workspace \"${workspace.name}\" has more than one agent"
281280
)
282281
return null
283282
}

src/main/kotlin/com/coder/toolbox/util/LinkMap.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.coder.toolbox.util
33
const val URL = "url"
44
const val TOKEN = "token"
55
const val WORKSPACE = "workspace"
6-
const val AGENT_ID = "agent_id"
6+
const val AGENT_NAME = "agent_name"
77
private const val IDE_PRODUCT_CODE = "ide_product_code"
88
private const val IDE_BUILD_NUMBER = "ide_build_number"
99
private const val FOLDER = "folder"
@@ -14,7 +14,7 @@ fun Map<String, String>.token() = this[TOKEN]
1414

1515
fun Map<String, String>.workspace() = this[WORKSPACE]
1616

17-
fun Map<String, String?>.agentID() = this[AGENT_ID]
17+
fun Map<String, String?>.agentName() = this[AGENT_NAME]
1818

1919
fun Map<String, String>.ideProductCode() = this[IDE_PRODUCT_CODE]
2020

0 commit comments

Comments
 (0)