Skip to content

Commit 2ce2aa1

Browse files
authored
fix: improve ssh config logic when workspaces change (#59)
- previously, ssh reconfiguration was triggered only when new workspaces were added, and the ssh config was generated only with the additional environments removing the configuration for the previous ones. This means that when a new workspace is created from the web dashboard, the old workspaces are no longer accessible via ssh from Toolbox - now, the logic ensures ssh reconfiguration happens whenever the set of environments changes (including additions or removals), making it more robust, and configuration happens for all valid workspaces. - resolves #14
1 parent ddfffe1 commit 2ce2aa1

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
- SSH config is regenerated correctly when Workspaces are added or removed
8+
59
## 0.1.0 - 2025-04-01
610

711
### Added

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ class CoderRemoteEnvironment(
194194
*/
195195
override fun equals(other: Any?): Boolean {
196196
if (other == null) return false
197-
if (this === other) return true // Note the triple ===
197+
if (this === other) return true
198198
if (other !is CoderRemoteEnvironment) return false
199-
if (id != other.id) return false
200-
return true
199+
return id == other.id
201200
}
202201

203202
/**

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

+5-6
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ class CoderRemoteProvider(
113113
return@launch
114114
}
115115

116-
// Reconfigure if a new environment is found.
117-
// TODO@JB: Should we use the add/remove listeners instead?
118-
val newEnvironments = resolvedEnvironments.subtract(lastEnvironments)
119-
if (newEnvironments.isNotEmpty()) {
120-
context.logger.info("Found new environment(s), reconfiguring CLI: $newEnvironments")
121-
cli.configSsh(newEnvironments.map { it.name }.toSet())
116+
117+
// Reconfigure if environments changed.
118+
if (lastEnvironments.size != resolvedEnvironments.size || lastEnvironments != resolvedEnvironments) {
119+
context.logger.info("Workspaces have changed, reconfiguring CLI: $resolvedEnvironments")
120+
cli.configSsh(resolvedEnvironments.map { it.name }.toSet())
122121
}
123122

124123
environments.update {

0 commit comments

Comments
 (0)