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

Commitc8e503e

Browse files
committed
Support agent ID parameter
1 parent42c2851 commitc8e503e

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

‎src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import java.net.URL
2323
privateconstvalURL="url"
2424
privateconstvalTOKEN="token"
2525
privateconstvalWORKSPACE="workspace"
26-
privateconstvalAGENT="agent"
26+
privateconstvalAGENT_NAME="agent"
27+
privateconstvalAGENT_ID="agent_id"
2728
privateconstvalFOLDER="folder"
2829
privateconstvalIDE_DOWNLOAD_LINK="ide_download_link"
2930
privateconstvalIDE_PRODUCT_CODE="ide_product_code"
@@ -72,14 +73,23 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
7273
}
7374

7475
// If the agent is missing and the workspace has only one, use that.
75-
val agent=if (!parameters[AGENT].isNullOrBlank())
76-
agents.firstOrNull { it.name=="$workspaceName.${parameters[AGENT]}"}
76+
// Prefer the ID over the name if both are set.
77+
val agent=if (!parameters[AGENT_ID].isNullOrBlank())
78+
agents.firstOrNull {it.agentID.toString()== parameters[AGENT_ID]}
79+
elseif (!parameters[AGENT_NAME].isNullOrBlank())
80+
agents.firstOrNull { it.name=="$workspaceName.${parameters[AGENT_NAME]}"}
7781
elseif (agents.size==1) agents.first()
7882
elsenull
7983

8084
if (agent==null) {
81-
// TODO: Show a dropdown and ask for an agent.
82-
throwIllegalArgumentException("Query parameter\"$AGENT\" is missing")
85+
if (parameters[AGENT_ID].isNullOrBlank()&& parameters[AGENT_NAME].isNullOrBlank()) {
86+
// TODO: Show a dropdown and ask for an agent.
87+
throwIllegalArgumentException("Unable to determine which agent to connect to; one of\"$AGENT_NAME\" or\"$AGENT_ID\" must be set because\"$workspaceName\" has more than one agent")
88+
}elseif (parameters[AGENT_ID].isNullOrBlank()) {
89+
throwIllegalArgumentException("The workspace\"$workspaceName\" does not have an agent with ID\"${parameters[AGENT_ID]}\"")
90+
}else {
91+
throwIllegalArgumentException("The workspace\"$workspaceName\" does not have an agent named\"${parameters[AGENT_NAME]}\"")
92+
}
8393
}
8494

8595
if (agent.agentStatus.pending()) {

‎src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import javax.swing.Icon
1414
// iterate over the list we can add the workspace row if it has no agents
1515
// otherwise iterate over the agents and then flatten the result.
1616
data classWorkspaceAgentModel(
17+
valagentID:UUID?,
1718
valworkspaceID:UUID,
1819
valworkspaceName:String,
1920
valname:String,// Name of the workspace OR the agent if this is for an agent.

‎src/main/kotlin/com/coder/gateway/sdk/v2/models/Workspace.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fun Workspace.toAgentModels(resources: List<WorkspaceResource> = this.latestBuil
3535
val wam= resources.filter { it.agents!=null }.flatMap { it.agents!! }.map { agent->
3636
val workspaceWithAgentName="${this.name}.${agent.name}"
3737
val wm=WorkspaceAgentModel(
38+
agent.id,
3839
this.id,
3940
this.name,
4041
workspaceWithAgentName,
@@ -55,6 +56,7 @@ fun Workspace.toAgentModels(resources: List<WorkspaceResource> = this.latestBuil
5556
}.toSet()
5657
if (wam.isNullOrEmpty()) {
5758
val wm=WorkspaceAgentModel(
59+
null,
5860
this.id,
5961
this.name,
6062
this.name,

‎src/test/groovy/DataGen.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.coder.gateway.sdk.v2.models.WorkspaceTransition
77
classDataGen {
88
staticWorkspaceAgentModelworkspace(Stringname,StringworkspaceName= name) {
99
returnnewWorkspaceAgentModel(
10+
UUID.randomUUID(),
1011
UUID.randomUUID(),
1112
workspaceName,
1213
name,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp