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

fix: improve ssh config logic when workspaces change #59

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- SSH config is regenerated correctly when Workspaces are added or removed

## 0.1.0 - 2025-04-01

### Added
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ class CoderRemoteEnvironment(
*/
override fun equals(other: Any?): Boolean {
if (other == null) return false
if (this === other) return true // Note the triple ===
if (this === other) return true
if (other !is CoderRemoteEnvironment) return false
if (id != other.id) return false
return true
return id == other.id
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ class CoderRemoteProvider(
return@launch
}

// Reconfigure if a new environment is found.
// TODO@JB: Should we use the add/remove listeners instead?
val newEnvironments = resolvedEnvironments.subtract(lastEnvironments)
if (newEnvironments.isNotEmpty()) {
context.logger.info("Found new environment(s), reconfiguring CLI: $newEnvironments")
cli.configSsh(newEnvironments.map { it.name }.toSet())

// Reconfigure if environments changed.
if (lastEnvironments.size != resolvedEnvironments.size || lastEnvironments != resolvedEnvironments) {
context.logger.info("Workspaces have changed, reconfiguring CLI: $resolvedEnvironments")
cli.configSsh(resolvedEnvironments.map { it.name }.toSet())
}

environments.update {
Expand Down
Loading