Skip to content

Commit 37dd4c3

Browse files
committed
chore: remove unused code
1 parent d706582 commit 37dd4c3

File tree

5 files changed

+9
-185
lines changed

5 files changed

+9
-185
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CoderRemoteProvider(
6464
// On the first load, automatically log in if we can.
6565
private var firstRun = true
6666
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
67-
private var coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(context.deploymentUrl?.first ?: ""))
67+
private var coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(context.deploymentUrl.toString()))
6868
private val linkHandler = CoderProtocolHandler(context, dialogUi, isInitialized)
6969
override val environments: MutableStateFlow<LoadableState<List<RemoteProviderEnvironment>>> = MutableStateFlow(
7070
LoadableState.Loading
Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.coder.toolbox
22

3-
import com.coder.toolbox.settings.SettingSource
43
import com.coder.toolbox.store.CoderSecretsStore
54
import com.coder.toolbox.store.CoderSettingsStore
65
import com.coder.toolbox.util.toURL
@@ -13,6 +12,7 @@ import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentStateColorPalette
1312
import com.jetbrains.toolbox.api.remoteDev.ui.EnvironmentUiPageManager
1413
import com.jetbrains.toolbox.api.ui.ToolboxUi
1514
import kotlinx.coroutines.CoroutineScope
15+
import java.net.URL
1616

1717
data class CoderToolboxContext(
1818
val ui: ToolboxUi,
@@ -37,31 +37,11 @@ data class CoderToolboxContext(
3737
* 3. CODER_URL.
3838
* 4. URL in global cli config.
3939
*/
40-
val deploymentUrl: Pair<String, SettingSource>?
41-
get() = this.secrets.lastDeploymentURL.let {
42-
if (it.isNotBlank()) {
43-
it to SettingSource.LAST_USED
44-
} else {
45-
this.settingsStore.defaultURL()
40+
val deploymentUrl: URL
41+
get() {
42+
if (this.secrets.lastDeploymentURL.isNotBlank()) {
43+
return this.secrets.lastDeploymentURL.toURL()
4644
}
45+
return this.settingsStore.defaultURL.toURL()
4746
}
48-
49-
/**
50-
* Try to find a token.
51-
*
52-
* Order of preference:
53-
*
54-
* 1. Last used token, if it was for this deployment.
55-
* 2. Token on disk for this deployment.
56-
* 3. Global token for Coder, if it matches the deployment.
57-
*/
58-
fun getToken(deploymentURL: String?): Pair<String, SettingSource>? = this.secrets.lastToken.let {
59-
if (it.isNotBlank() && this.secrets.lastDeploymentURL == deploymentURL) {
60-
it to SettingSource.LAST_USED
61-
} else {
62-
if (deploymentURL != null) {
63-
this.settingsStore.token(deploymentURL.toURL())
64-
} else null
65-
}
66-
}
6747
}

src/main/kotlin/com/coder/toolbox/settings/ReadOnlyCoderSettings.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ReadOnlyCoderSettings {
1010
/**
1111
* The default URL to show in the connection window.
1212
*/
13-
val defaultURL: String?
13+
val defaultURL: String
1414

1515
/**
1616
* Used to download the Coder CLI which is necessary to proxy SSH
@@ -116,16 +116,6 @@ interface ReadOnlyCoderSettings {
116116
*/
117117
val networkInfoDir: String
118118

119-
/**
120-
* The default URL to show in the connection window.
121-
*/
122-
fun defaultURL(): Pair<String, SettingSource>?
123-
124-
/**
125-
* Given a deployment URL, try to find a token for it if required.
126-
*/
127-
fun token(deploymentURL: URL): Pair<String, SettingSource>?
128-
129119
/**
130120
* Where the specified deployment should put its data.
131121
*/

src/main/kotlin/com/coder/toolbox/store/CoderSettingsStore.kt

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.coder.toolbox.store
33
import com.coder.toolbox.settings.Environment
44
import com.coder.toolbox.settings.ReadOnlyCoderSettings
55
import com.coder.toolbox.settings.ReadOnlyTLSSettings
6-
import com.coder.toolbox.settings.SettingSource
76
import com.coder.toolbox.util.Arch
87
import com.coder.toolbox.util.OS
98
import com.coder.toolbox.util.expand
@@ -35,7 +34,7 @@ class CoderSettingsStore(
3534
) : ReadOnlyTLSSettings
3635

3736
// Properties implementation
38-
override val defaultURL: String? get() = store[DEFAULT_URL]
37+
override val defaultURL: String get() = store[DEFAULT_URL] ?: "https://dev.coder.com"
3938
override val binarySource: String? get() = store[BINARY_SOURCE]
4039
override val binaryDirectory: String? get() = store[BINARY_DIRECTORY]
4140
override val defaultCliBinaryNameByOsAndArch: String get() = getCoderCLIForOS(getOS(), getArch())
@@ -71,48 +70,6 @@ class CoderSettingsStore(
7170
.normalize()
7271
.toString()
7372

74-
/**
75-
* The default URL to show in the connection window.
76-
*/
77-
override fun defaultURL(): Pair<String, SettingSource>? {
78-
val envURL = env.get(CODER_URL)
79-
if (!defaultURL.isNullOrEmpty()) {
80-
return defaultURL!! to SettingSource.SETTINGS
81-
} else if (envURL.isNotBlank()) {
82-
return envURL to SettingSource.ENVIRONMENT
83-
} else {
84-
val (configUrl, _) = readConfig(Path.of(globalConfigDir))
85-
if (!configUrl.isNullOrBlank()) {
86-
return configUrl to SettingSource.CONFIG
87-
}
88-
}
89-
return null
90-
}
91-
92-
/**
93-
* Given a deployment URL, try to find a token for it if required.
94-
*/
95-
override fun token(deploymentURL: URL): Pair<String, SettingSource>? {
96-
// No need to bother if we do not need token auth anyway.
97-
if (!requireTokenAuth) {
98-
return null
99-
}
100-
// Try the deployment's config directory. This could exist if someone
101-
// has entered a URL that they are not currently connected to, but have
102-
// connected to in the past.
103-
val (_, deploymentToken) = readConfig(dataDir(deploymentURL).resolve("config"))
104-
if (!deploymentToken.isNullOrBlank()) {
105-
return deploymentToken to SettingSource.DEPLOYMENT_CONFIG
106-
}
107-
// Try the global config directory, in case they previously set up the
108-
// CLI with this URL.
109-
val (configUrl, configToken) = readConfig(Path.of(globalConfigDir))
110-
if (configUrl == deploymentURL.toString() && !configToken.isNullOrBlank()) {
111-
return configToken to SettingSource.CONFIG
112-
}
113-
return null
114-
}
115-
11673
/**
11774
* Where the specified deployment should put its data.
11875
*/

src/test/kotlin/com/coder/toolbox/settings/CoderSettingsTest.kt

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.coder.toolbox.settings
33
import com.coder.toolbox.store.BINARY_NAME
44
import com.coder.toolbox.store.CODER_SSH_CONFIG_OPTIONS
55
import com.coder.toolbox.store.CoderSettingsStore
6-
import com.coder.toolbox.store.DEFAULT_URL
76
import com.coder.toolbox.store.DISABLE_AUTOSTART
87
import com.coder.toolbox.store.ENABLE_BINARY_DIR_FALLBACK
98
import com.coder.toolbox.store.ENABLE_DOWNLOADS
@@ -277,108 +276,6 @@ internal class CoderSettingsTest {
277276
assertEquals(false, settings.readOnly().requireTokenAuth)
278277
}
279278

280-
@Test
281-
fun testDefaultURL() {
282-
val tmp = Path.of(System.getProperty("java.io.tmpdir"))
283-
val dir = tmp.resolve("coder-toolbox-test/test-default-url")
284-
var env = Environment(mapOf("CODER_CONFIG_DIR" to dir.toString()))
285-
dir.toFile().deleteRecursively()
286-
287-
// No config.
288-
var settings = CoderSettingsStore(pluginTestSettingsStore(), env, logger)
289-
assertEquals(null, settings.defaultURL())
290-
291-
// Read from global config.
292-
val globalConfigPath = Path.of(settings.readOnly().globalConfigDir)
293-
globalConfigPath.toFile().mkdirs()
294-
globalConfigPath.resolve("url").toFile().writeText("url-from-global-config")
295-
settings = CoderSettingsStore(pluginTestSettingsStore(), env, logger)
296-
assertEquals("url-from-global-config" to SettingSource.CONFIG, settings.defaultURL())
297-
298-
// Read from environment.
299-
env =
300-
Environment(
301-
mapOf(
302-
"CODER_URL" to "url-from-env",
303-
"CODER_CONFIG_DIR" to dir.toString(),
304-
),
305-
)
306-
settings = CoderSettingsStore(pluginTestSettingsStore(), env, logger)
307-
assertEquals("url-from-env" to SettingSource.ENVIRONMENT, settings.defaultURL())
308-
309-
// Read from settings.
310-
settings =
311-
CoderSettingsStore(
312-
pluginTestSettingsStore(
313-
DEFAULT_URL to "url-from-settings",
314-
),
315-
env,
316-
logger
317-
)
318-
assertEquals("url-from-settings" to SettingSource.SETTINGS, settings.defaultURL())
319-
}
320-
321-
@Test
322-
fun testToken() {
323-
val tmp = Path.of(System.getProperty("java.io.tmpdir"))
324-
val url = URL("http://test.deployment.coder.com")
325-
val dir = tmp.resolve("coder-toolbox-test/test-default-token")
326-
val env =
327-
Environment(
328-
mapOf(
329-
"CODER_CONFIG_DIR" to dir.toString(),
330-
"LOCALAPPDATA" to dir.toString(),
331-
"XDG_DATA_HOME" to dir.toString(),
332-
"HOME" to dir.toString(),
333-
),
334-
)
335-
dir.toFile().deleteRecursively()
336-
337-
// No config.
338-
var settings = CoderSettingsStore(pluginTestSettingsStore(), env, logger)
339-
assertEquals(null, settings.readOnly().token(url))
340-
341-
val globalConfigPath = Path.of(settings.readOnly().globalConfigDir)
342-
globalConfigPath.toFile().mkdirs()
343-
globalConfigPath.resolve("url").toFile().writeText(url.toString())
344-
globalConfigPath.resolve("session").toFile().writeText("token-from-global-config")
345-
346-
// Ignore global config if it does not match.
347-
assertEquals(null, settings.readOnly().token(URL("http://some.random.url")))
348-
349-
// Read from global config.
350-
assertEquals("token-from-global-config" to SettingSource.CONFIG, settings.readOnly().token(url))
351-
352-
// Compares exactly.
353-
assertEquals(null, settings.readOnly().token(url.withPath("/test")))
354-
355-
val deploymentConfigPath = settings.readOnly().dataDir(url).resolve("config")
356-
deploymentConfigPath.toFile().mkdirs()
357-
deploymentConfigPath.resolve("url").toFile().writeText("url-from-deployment-config")
358-
deploymentConfigPath.resolve("session").toFile().writeText("token-from-deployment-config")
359-
360-
// Read from deployment config.
361-
assertEquals("token-from-deployment-config" to SettingSource.DEPLOYMENT_CONFIG, settings.readOnly().token(url))
362-
363-
// Only compares host .
364-
assertEquals(
365-
"token-from-deployment-config" to SettingSource.DEPLOYMENT_CONFIG,
366-
settings.readOnly().token(url.withPath("/test"))
367-
)
368-
369-
// Ignore if using mTLS.
370-
settings =
371-
CoderSettingsStore(
372-
pluginTestSettingsStore(
373-
TLS_KEY_PATH to "key",
374-
TLS_CERT_PATH to "cert",
375-
),
376-
env,
377-
logger
378-
)
379-
assertEquals(null, settings.readOnly().token(url))
380-
}
381-
382279
@Test
383280
fun testDefaults() {
384281
// Test defaults for the remaining settings.

0 commit comments

Comments
 (0)