@@ -18,6 +18,7 @@ import kotlinx.coroutines.launch
18
18
import kotlinx.coroutines.yield
19
19
import okhttp3.OkHttpClient
20
20
import java.net.HttpURLConnection
21
+ import java.net.URI
21
22
import java.net.URL
22
23
23
24
open class CoderProtocolHandler (
@@ -35,19 +36,19 @@ open class CoderProtocolHandler(
35
36
* connectable state.
36
37
*/
37
38
suspend fun handle (
38
- parameters : Map < String , String > ,
39
+ uri : URI ,
39
40
onReinitialize : suspend (CoderRestClient , CoderCLIManager ) -> Unit
40
41
) {
41
- val deploymentURL =
42
- parameters.url() ? : dialogUi.ask(
43
- context.i18n.ptrl(" Deployment URL" ),
44
- context.i18n.ptrl(" Enter the full URL of your Coder deployment" )
45
- )
42
+ val params = uri.toQueryParameters()
43
+
44
+ val deploymentURL = params.url() ? : askUrl()
46
45
if (deploymentURL.isNullOrBlank()) {
47
- throw MissingArgumentException (" Query parameter \" $URL \" is missing" )
46
+ context.logger.error(" Query parameter \" $URL \" is missing from URI $uri " )
47
+ context.ui.showErrorInfoPopup(MissingArgumentException (" Can't handle URI because query parameter \" $URL \" is missing" ))
48
+ return
48
49
}
49
50
50
- val queryTokenRaw = parameters .token()
51
+ val queryTokenRaw = params .token()
51
52
val queryToken = if (! queryTokenRaw.isNullOrBlank()) {
52
53
Pair (queryTokenRaw, Source .QUERY )
53
54
} else {
@@ -61,7 +62,7 @@ open class CoderProtocolHandler(
61
62
62
63
// TODO: Show a dropdown and ask for the workspace if missing.
63
64
val workspaceName =
64
- parameters .workspace() ? : throw MissingArgumentException (" Query parameter \" $WORKSPACE \" is missing" )
65
+ params .workspace() ? : throw MissingArgumentException (" Query parameter \" $WORKSPACE \" is missing" )
65
66
66
67
val workspaces = restClient.workspaces()
67
68
val workspace =
@@ -99,7 +100,7 @@ open class CoderProtocolHandler(
99
100
}
100
101
101
102
// TODO: Show a dropdown and ask for an agent if missing.
102
- val agent = getMatchingAgent(parameters , workspace)
103
+ val agent = getMatchingAgent(params , workspace)
103
104
val status = WorkspaceAndAgentStatus .from(workspace, agent)
104
105
105
106
if (status.pending()) {
@@ -147,6 +148,15 @@ open class CoderProtocolHandler(
147
148
}
148
149
}
149
150
151
+ private suspend fun askUrl (): String? {
152
+ context.ui.showWindow()
153
+ context.envPageManager.showPluginEnvironmentsPage(false )
154
+ return dialogUi.ask(
155
+ context.i18n.ptrl(" Deployment URL" ),
156
+ context.i18n.ptrl(" Enter the full URL of your Coder deployment" )
157
+ )
158
+ }
159
+
150
160
/* *
151
161
* Return an authenticated Coder CLI, asking for the token as long as it
152
162
* continues to result in an authentication failure and token authentication
0 commit comments