Skip to content

Commit 3ac53e8

Browse files
authored
impl: ability to customize the links to Dashboard (#211)
Some clients (Netflix in this specific case) rely on mainly their own dashboard tools instead of the Coder one. Two main reasons that were mentioned by Netflix: - aggregate many dev tools in a unified internal console - specific platform/security needs that their own UI handles better For this reason they would like the actions that open up the Coder Dashboard (`Create workspace` and `Open in dashboard`) to be fully customizable, and allow clients to override the URL. For `Create workspace` we now have a config that defaults $lastDeploymentUrl/templates, but it can be replaced with a complete new URL. It also supports `$workspaceOwner` as a placeholder that is replaced by the plugin with the username that logged in. For `Open in dashboard` a full URL can be provided and we also introduced two placeholders `$workspaceOwner` and `$workspaceName` which will be replaced by the plugin but only for this action. For now the decision is to not allow configuration from UI since Netflix is the only target for this change, and they deploy at scale a templated settings.json.
1 parent 947be1c commit 3ac53e8

File tree

8 files changed

+47
-9
lines changed

8 files changed

+47
-9
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ storage paths. The options can be configured from the plugin's main Workspaces p
360360
- `Header command` command that outputs additional HTTP headers. Each line of output must be in the format key=value.
361361
The environment variable CODER_URL will be available to the command process.
362362

363+
- `lastDeploymentURL` the last Coder deployment URL that Coder Toolbox successfully authenticated to.
364+
365+
- `workspaceViewUrl` specifies the dashboard page full URL where users can view details about a workspace.
366+
Helpful for customers that have their own in-house dashboards. Defaults to the Coder deployment workspace page.
367+
This setting supports `$workspaceOwner` and `$workspaceName` as placeholders.
368+
369+
- `workspaceCreateUrl` specifies the dashboard page full URL where users can create new workspaces.
370+
Helpful for customers that have their own in-house dashboards. Defaults to the Coder deployment templates page.
371+
This setting supports `$workspaceOwner` as placeholder with the replacing value being the username that logged in.
372+
363373
### TLS settings
364374

365375
The following options control the secure communication behavior of the plugin with Coder deployment and its available

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=0.7.1
1+
version=0.7.3
22
group=com.coder.toolbox
33
name=coder-toolbox

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ class CoderRemoteEnvironment(
9191
}
9292
actions.add(
9393
Action(context, "Open in dashboard") {
94+
val urlTemplate = context.settingsStore.workspaceViewUrl
95+
?: client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()
96+
val url = urlTemplate
97+
.replace("\$workspaceOwner", "${workspace.ownerName}")
98+
.replace("\$workspaceName", workspace.name)
9499
context.desktop.browse(
95-
client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()
100+
url
96101
) {
97102
context.ui.showErrorInfoPopup(it)
98103
}

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ class CoderRemoteProvider(
224224
override val additionalPluginActions: StateFlow<List<ActionDescription>> = MutableStateFlow(
225225
listOf(
226226
Action(context, "Create workspace") {
227-
context.desktop.browse(client?.url?.withPath("/templates").toString()) {
227+
val url = context.settingsStore.workspaceCreateUrl ?: client?.url?.withPath("/templates").toString()
228+
context.desktop.browse(
229+
url
230+
.replace("\$workspaceOwner", client?.me()?.username ?: "")
231+
) {
228232
context.ui.showErrorInfoPopup(it)
229233
}
230234
},

src/main/kotlin/com/coder/toolbox/settings/ReadOnlyCoderSettings.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ interface ReadOnlyCoderSettings {
137137
*/
138138
val sshConfigOptions: String?
139139

140+
/**
141+
* A custom full URL to the dashboard page used for viewing details about a workspace.
142+
* Supports `$workspaceOwner` and `$workspaceName` as placeholders.
143+
*/
144+
val workspaceViewUrl: String?
145+
146+
/**
147+
* A custom full URL to the dashboard page used for creating workspaces.
148+
* Supports `$workspaceOwner` as placeholder.
149+
*/
150+
val workspaceCreateUrl: String?
140151

141152
/**
142153
* The path where network information for SSH hosts are stored

src/main/kotlin/com/coder/toolbox/store/CoderSettingsStore.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class CoderSettingsStore(
8080
.normalize()
8181
.toString()
8282

83+
override val workspaceViewUrl: String?
84+
get() = store[WORKSPACE_VIEW_URL]
85+
override val workspaceCreateUrl: String?
86+
get() = store[WORKSPACE_CREATE_URL]
87+
8388
/**
8489
* Where the specified deployment should put its data.
8590
*/

src/main/kotlin/com/coder/toolbox/store/StoreKeys.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ internal const val SSH_CONFIG_OPTIONS = "sshConfigOptions"
4646

4747
internal const val NETWORK_INFO_DIR = "networkInfoDir"
4848

49+
internal const val WORKSPACE_VIEW_URL = "workspaceViewUrl"
50+
internal const val WORKSPACE_CREATE_URL = "workspaceCreateUrl"
51+
4952
internal const val SSH_AUTO_CONNECT_PREFIX = "ssh_auto_connect_"
5053

src/test/kotlin/com/coder/toolbox/util/URLExtensionsTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ internal class URLExtensionsTest {
99
@Test
1010
fun testToURL() {
1111
assertEquals(
12-
URL("https", "localhost", 8080, "/path"),
13-
"https://localhost:8080/path".toURL(),
12+
expected = URI.create("https://localhost:8080/path").toURL(),
13+
actual = "https://localhost:8080/path".toURL(),
1414
)
1515
}
1616

1717
@Test
1818
fun testWithPath() {
1919
assertEquals(
20-
URL("https", "localhost", 8080, "/foo/bar"),
21-
URL("https", "localhost", 8080, "/").withPath("/foo/bar"),
20+
expected = "https://localhost:8080/foo/bar".toURL(),
21+
actual = "https://localhost:8080/".toURL().withPath("/foo/bar"),
2222
)
2323

2424
assertEquals(
25-
URL("https", "localhost", 8080, "/foo/bar"),
26-
URL("https", "localhost", 8080, "/old/path").withPath("/foo/bar"),
25+
expected = "https://localhost:8080/foo/bar".toURL(),
26+
actual = "https://localhost:8080/old/path".toURL().withPath("/foo/bar"),
2727
)
2828
}
2929

0 commit comments

Comments
 (0)