@@ -80,6 +80,8 @@ class CoderRemoteProvider(
80
80
)
81
81
)
82
82
83
+ private val errorBuffer = mutableListOf<Throwable >()
84
+
83
85
/* *
84
86
* With the provided client, start polling for workspaces. Every time a new
85
87
* workspace is added, reconfigure SSH using the provided cli (including the
@@ -162,13 +164,12 @@ class CoderRemoteProvider(
162
164
if (elapsed > POLL_INTERVAL * 2 ) {
163
165
context.logger.info(" wake-up from an OS sleep was detected" )
164
166
} else {
165
- context.logger.error(ex, " workspace polling error encountered, trying to auto-login " )
167
+ context.logger.error(ex, " workspace polling error encountered" )
166
168
if (ex is APIResponseException && ex.isTokenExpired) {
167
169
WorkspaceConnectionManager .shouldEstablishWorkspaceConnections = true
168
170
close()
169
- // force auto-login
170
- firstRun = true
171
171
context.envPageManager.showPluginEnvironmentsPage()
172
+ errorBuffer.add(ex)
172
173
break
173
174
}
174
175
}
@@ -194,9 +195,6 @@ class CoderRemoteProvider(
194
195
* first page.
195
196
*/
196
197
private fun logout () {
197
- // Keep the URL and token to make it easy to log back in, but set
198
- // rememberMe to false so we do not try to automatically log in.
199
- context.secrets.rememberMe = false
200
198
WorkspaceConnectionManager .reset()
201
199
close()
202
200
}
@@ -358,22 +356,17 @@ class CoderRemoteProvider(
358
356
override fun getOverrideUiPage (): UiPage ? {
359
357
// Show the setup page if we have not configured the client yet.
360
358
if (client == null ) {
361
- val errorBuffer = mutableListOf<Throwable >()
362
359
// When coming back to the application, initializeSession immediately.
363
- val autoSetup = shouldDoAutoSetup()
364
- context.secrets.lastToken.let { lastToken ->
365
- context.secrets.lastDeploymentURL.let { lastDeploymentURL ->
366
- if (autoSetup && lastDeploymentURL.isNotBlank() && (lastToken.isNotBlank() || ! settings.requireTokenAuth)) {
367
- try {
368
- CoderCliSetupWizardState .goToStep(WizardStep .CONNECT )
369
- return CoderCliSetupWizardPage (context, settingsPage, visibilityState, true , ::onConnect)
370
- } catch (ex: Exception ) {
371
- errorBuffer.add(ex)
372
- }
373
- }
360
+ if (shouldDoAutoSetup()) {
361
+ try {
362
+ CoderCliSetupWizardState .goToStep(WizardStep .CONNECT )
363
+ return CoderCliSetupWizardPage (context, settingsPage, visibilityState, true , ::onConnect)
364
+ } catch (ex: Exception ) {
365
+ errorBuffer.add(ex)
366
+ } finally {
367
+ firstRun = false
374
368
}
375
369
}
376
- firstRun = false
377
370
378
371
// Login flow.
379
372
val setupWizardPage =
@@ -382,21 +375,24 @@ class CoderRemoteProvider(
382
375
errorBuffer.forEach {
383
376
setupWizardPage.notify(" Error encountered" , it)
384
377
}
378
+ errorBuffer.clear()
385
379
// and now reset the errors, otherwise we show it every time on the screen
386
380
return setupWizardPage
387
381
}
388
382
return null
389
383
}
390
384
391
- private fun shouldDoAutoSetup (): Boolean = firstRun && context.secrets.rememberMe == true
385
+ /* *
386
+ * Auto-login only on first the firs run if there is a url & token configured or the auth
387
+ * should be done via certificates.
388
+ */
389
+ private fun shouldDoAutoSetup (): Boolean = firstRun && (context.secrets.canAutoLogin || ! settings.requireTokenAuth)
392
390
393
391
private fun onConnect (client : CoderRestClient , cli : CoderCLIManager ) {
394
392
// Store the URL and token for use next time.
395
393
context.secrets.lastDeploymentURL = client.url.toString()
396
394
context.secrets.lastToken = client.token ? : " "
397
395
context.secrets.storeTokenFor(client.url, context.secrets.lastToken)
398
- // Currently we always remember, but this could be made an option.
399
- context.secrets.rememberMe = true
400
396
this .client = client
401
397
pollJob?.cancel()
402
398
environments.showLoadingMessage()
0 commit comments