Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda7656f

Browse files
authored
Impl: update ssh config when settings change (#51)
- right now the ssh config is triggered only when at the login and onlywhen new workspaces arecreated. In the last case, the ssh config updates only the new sections.- but the user can go into settings page and enable or disable thewildcard ssh config. With this patchafter the user hits Save, the ssh re-configuration is triggered, withoutthe need to restart Toolbox.Also a major fix - read only settings acted as snapshots in the sensethat they did not reflect any subsequent update to the underlying storebecause updates create a new readonly instance- with this patch we simplified the code even more by exposing areadonly interface with all of theimplementation in the CoderSettingsStore. PluginSettingsStore andEnvironments are the only persist-able stores.- because read only instances share the same settings store instancesany update on the writable will reflect on the readable instances as well.
1 parent09e15db commitda7656f

File tree

9 files changed

+387
-314
lines changed

9 files changed

+387
-314
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,8 @@ class CoderRemoteEnvironment(
204204
* Companion to equals, for sets.
205205
*/
206206
overridefunhashCode():Int= id.hashCode()
207+
208+
overridefuntoString():String {
209+
return"CoderRemoteEnvironment(name='$name')"
210+
}
207211
}

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ import com.jetbrains.toolbox.api.remoteDev.RemoteProvider
2020
importcom.jetbrains.toolbox.api.remoteDev.RemoteProviderEnvironment
2121
importcom.jetbrains.toolbox.api.ui.actions.ActionDescription
2222
importcom.jetbrains.toolbox.api.ui.components.UiPage
23+
importkotlinx.coroutines.ExperimentalCoroutinesApi
2324
importkotlinx.coroutines.Job
24-
importkotlinx.coroutines.delay
25+
importkotlinx.coroutines.channels.Channel
2526
importkotlinx.coroutines.flow.MutableStateFlow
2627
importkotlinx.coroutines.flow.StateFlow
2728
importkotlinx.coroutines.flow.update
2829
importkotlinx.coroutines.isActive
2930
importkotlinx.coroutines.launch
31+
importkotlinx.coroutines.selects.onTimeout
32+
importkotlinx.coroutines.selects.select
3033
importokhttp3.OkHttpClient
3134
importjava.net.URI
3235
importjava.net.URL
@@ -35,18 +38,20 @@ import kotlin.time.Duration.Companion.seconds
3538
importcom.jetbrains.toolbox.api.ui.components.AccountDropdownFieldasDropDownMenu
3639
importcom.jetbrains.toolbox.api.ui.components.AccountDropdownFieldasdropDownFactory
3740

41+
@OptIn(ExperimentalCoroutinesApi::class)
3842
classCoderRemoteProvider(
3943
privatevalcontext:CoderToolboxContext,
4044
privatevalhttpClient:OkHttpClient,
4145
) : RemoteProvider("Coder") {
4246
// Current polling job.
4347
privatevar pollJob:Job?=null
44-
privatevar lastEnvironments:Set<CoderRemoteEnvironment>?=null
48+
privateval lastEnvironments= mutableSetOf<CoderRemoteEnvironment>()
4549

46-
privatevalcSettings= context.settingsStore.readOnly()
50+
privatevalsettings= context.settingsStore.readOnly()
4751

4852
// Create our services from the Toolbox ones.
49-
privateval settingsPage:CoderSettingsPage=CoderSettingsPage(context)
53+
privateval triggerSshConfig=Channel<Boolean>(Channel.CONFLATED)
54+
privateval settingsPage:CoderSettingsPage=CoderSettingsPage(context, triggerSshConfig)
5055
privateval dialogUi=DialogUi(context)
5156

5257
// The REST client, if we are signed in
@@ -92,7 +97,7 @@ class CoderRemoteProvider(
9297
}?.map { agent->
9398
// If we have an environment already, update that.
9499
val env=CoderRemoteEnvironment(context, client, ws, agent)
95-
lastEnvironments?.firstOrNull { it== env }?.let {
100+
lastEnvironments.firstOrNull { it== env }?.let {
96101
it.update(ws, agent)
97102
it
98103
}?: env
@@ -107,9 +112,7 @@ class CoderRemoteProvider(
107112

108113
// Reconfigure if a new environment is found.
109114
// TODO@JB: Should we use the add/remove listeners instead?
110-
val newEnvironments= lastEnvironments
111-
?.let { resolvedEnvironments.subtract(it) }
112-
?: resolvedEnvironments
115+
val newEnvironments= resolvedEnvironments.subtract(lastEnvironments)
113116
if (newEnvironments.isNotEmpty()) {
114117
context.logger.info("Found new environment(s), reconfiguring CLI:$newEnvironments")
115118
cli.configSsh(newEnvironments.map { it.name }.toSet())
@@ -124,8 +127,10 @@ class CoderRemoteProvider(
124127
true
125128
}
126129
}
127-
128-
lastEnvironments= resolvedEnvironments
130+
lastEnvironments.apply {
131+
clear()
132+
addAll(resolvedEnvironments)
133+
}
129134
}catch (_:CancellationException) {
130135
context.logger.debug("${client.url} polling loop canceled")
131136
break
@@ -136,7 +141,17 @@ class CoderRemoteProvider(
136141
break
137142
}
138143
// TODO: Listening on a web socket might be better?
139-
delay(5.seconds)
144+
select<Unit> {
145+
onTimeout(5.seconds) {
146+
context.logger.trace("workspace poller waked up by the 5 seconds timeout")
147+
}
148+
triggerSshConfig.onReceive { shouldTrigger->
149+
if (shouldTrigger) {
150+
context.logger.trace("workspace poller waked up because it should reconfigure the ssh configurations")
151+
cli.configSsh(lastEnvironments.map { it.name }.toSet())
152+
}
153+
}
154+
}
140155
}
141156
}
142157

@@ -178,7 +193,7 @@ class CoderRemoteProvider(
178193
overridefunclose() {
179194
pollJob?.cancel()
180195
client?.close()
181-
lastEnvironments=null
196+
lastEnvironments.clear()
182197
environments.value=LoadableState.Value(emptyList())
183198
isInitialized.update {false }
184199
}
@@ -270,7 +285,7 @@ class CoderRemoteProvider(
270285
var autologinEx:Exception?=null
271286
context.secrets.lastToken.let { lastToken->
272287
context.secrets.lastDeploymentURL.let { lastDeploymentURL->
273-
if (autologin&& lastDeploymentURL.isNotBlank()&& (lastToken.isNotBlank()||!cSettings.requireTokenAuth)) {
288+
if (autologin&& lastDeploymentURL.isNotBlank()&& (lastToken.isNotBlank()||!settings.requireTokenAuth)) {
274289
try {
275290
return createConnectPage(URL(lastDeploymentURL), lastToken)
276291
}catch (ex:Exception) {
@@ -342,7 +357,7 @@ class CoderRemoteProvider(
342357
if (it.isNotBlank()&& context.secrets.lastDeploymentURL== deploymentURL.toString()) {
343358
it toSettingSource.LAST_USED
344359
}else {
345-
cSettings.token(deploymentURL)
360+
settings.token(deploymentURL)
346361
}
347362
}
348363

‎src/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.coder.toolbox.cli.ex.ResponseException
66
importcom.coder.toolbox.cli.ex.SSHConfigFormatException
77
importcom.coder.toolbox.sdk.v2.models.Workspace
88
importcom.coder.toolbox.sdk.v2.models.WorkspaceAgent
9-
importcom.coder.toolbox.settings.CoderSettings
9+
importcom.coder.toolbox.settings.ReadOnlyCoderSettings
1010
importcom.coder.toolbox.util.CoderHostnameVerifier
1111
importcom.coder.toolbox.util.InvalidVersionException
1212
importcom.coder.toolbox.util.OS
@@ -125,7 +125,7 @@ class CoderCLIManager(
125125
privatevaldeploymentURL:URL,
126126
privatevallogger:Logger,
127127
// Plugin configuration.
128-
privatevalsettings:CoderSettings,
128+
privatevalsettings:ReadOnlyCoderSettings,
129129
// If the binary directory is not writable, this can be used to force the
130130
// manager to download to the data directory instead.
131131
forceDownloadToData:Boolean =false,
@@ -267,21 +267,21 @@ class CoderCLIManager(
267267
"--url",
268268
escape(deploymentURL.toString()),
269269
if (!settings.headerCommand.isNullOrBlank())"--header-command"elsenull,
270-
if (!settings.headerCommand.isNullOrBlank()) escapeSubcommand(settings.headerCommand)elsenull,
270+
if (!settings.headerCommand.isNullOrBlank()) escapeSubcommand(settings.headerCommand!!)elsenull,
271271
"ssh",
272272
"--stdio",
273273
if (settings.disableAutostart&& feats.disableAutostart)"--disable-autostart"elsenull,
274274
)
275275
val proxyArgs= baseArgs+ listOfNotNull(
276276
if (!settings.sshLogDirectory.isNullOrBlank())"--log-dir"elsenull,
277-
if (!settings.sshLogDirectory.isNullOrBlank()) escape(settings.sshLogDirectory)elsenull,
277+
if (!settings.sshLogDirectory.isNullOrBlank()) escape(settings.sshLogDirectory!!)elsenull,
278278
if (feats.reportWorkspaceUsage)"--usage-app=jetbrains"elsenull,
279279
)
280280
val backgroundProxyArgs=
281281
baseArgs+ listOfNotNull(if (feats.reportWorkspaceUsage)"--usage-app=disable"elsenull)
282282
val extraConfig=
283283
if (!settings.sshConfigOptions.isNullOrBlank()) {
284-
"\n"+ settings.sshConfigOptions.prependIndent("")
284+
"\n"+ settings.sshConfigOptions!!.prependIndent("")
285285
}else {
286286
""
287287
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp