@@ -19,7 +19,6 @@ import com.coder.gateway.sdk.TemplateIconDownloader
19
19
import com.coder.gateway.sdk.ex.AuthenticationResponseException
20
20
import com.coder.gateway.sdk.ex.TemplateResponseException
21
21
import com.coder.gateway.sdk.ex.WorkspaceResponseException
22
- import com.coder.gateway.sdk.getOS
23
22
import com.coder.gateway.sdk.toURL
24
23
import com.coder.gateway.sdk.v2.models.Workspace
25
24
import com.coder.gateway.sdk.withPath
@@ -66,9 +65,6 @@ import java.awt.event.MouseListener
66
65
import java.awt.event.MouseMotionListener
67
66
import java.awt.font.TextAttribute
68
67
import java.awt.font.TextAttribute.UNDERLINE_ON
69
- import java.nio.file.Files
70
- import java.nio.file.Path
71
- import java.nio.file.Paths
72
68
import java.net.SocketTimeoutException
73
69
import javax.swing.Icon
74
70
import javax.swing.JCheckBox
@@ -364,45 +360,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
364
360
if (! url.isNullOrBlank() && ! token.isNullOrBlank()) {
365
361
return url to token
366
362
}
367
- return readConfig()
368
- }
369
-
370
- /* *
371
- * Return the URL and token from the CLI config.
372
- */
373
- private fun readConfig (): Pair <String ?, String ?> {
374
- val configDir = getConfigDir()
375
- logger.info(" Reading config from $configDir " )
376
- try {
377
- val url = Files .readString(configDir.resolve(" url" ))
378
- val token = Files .readString(configDir.resolve(" session" ))
379
- return url to token
380
- } catch (e: Exception ) {
381
- return null to null // Probably has not configured the CLI yet.
382
- }
383
- }
384
-
385
- /* *
386
- * Return the config directory used by the CLI.
387
- */
388
- private fun getConfigDir (): Path {
389
- var dir = System .getenv(" CODER_CONFIG_DIR" )
390
- if (! dir.isNullOrBlank()) {
391
- return Path .of(dir)
392
- }
393
- // The Coder CLI uses https://github.com/kirsle/configdir so this should
394
- // match how it behaves.
395
- return when (getOS()) {
396
- OS .WINDOWS -> Paths .get(System .getenv(" APPDATA" ), " coderv2" )
397
- OS .MAC -> Paths .get(System .getenv(" HOME" ), " Library/Application Support/coderv2" )
398
- else -> {
399
- dir = System .getenv(" XDG_CONFIG_HOME" )
400
- if (! dir.isNullOrBlank()) {
401
- return Paths .get(dir, " coderv2" )
402
- }
403
- return Paths .get(System .getenv(" HOME" ), " .config/coderv2" )
404
- }
405
- }
363
+ return CoderCLIManager .readConfig()
406
364
}
407
365
408
366
private fun updateWorkspaceActions () {
@@ -518,7 +476,7 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
518
476
if (openBrowser && ! localWizardModel.useExistingToken) {
519
477
BrowserUtil .browse(getTokenUrl)
520
478
} else if (localWizardModel.useExistingToken) {
521
- val (url, token) = readConfig()
479
+ val (url, token) = CoderCLIManager . readConfig()
522
480
if (url == localWizardModel.coderURL && ! token.isNullOrBlank()) {
523
481
logger.info(" Injecting valid token from CLI config" )
524
482
localWizardModel.token = token
0 commit comments