Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/main/kotlin/com/coder/gateway/util/LinkHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
indicator,
)

var workspace: Workspace

Check warning on line 74 in src/main/kotlin/com/coder/gateway/util/LinkHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Local 'var' is never modified and can be declared as 'val'

Variable is never modified, so it can be declared using 'val'
var workspaces: List<Workspace> = emptyList()
var workspacesAndAgents: Set<Pair<Workspace, WorkspaceAgent>> = emptySet()
if (cli.features.wildcardSSH) {
Expand Down Expand Up @@ -327,25 +327,24 @@
}

// If the agent is missing and the workspace has only one, use that.
// Prefer the ID over the name if both are set.
val agent =
if (!parameters.agentID().isNullOrBlank()) {
agents.firstOrNull { it.id.toString() == parameters.agentID() }
} else if (!parameters.agentName().isNullOrBlank()) {
agents.firstOrNull { it.name == parameters.agentName() }
} else if (agents.size == 1) {
agents.first()
} else {
null
}
// Prefer the name over the id if both are set.
val agent = if (!parameters.agentName().isNullOrBlank()) {
agents.firstOrNull { it.name == parameters.agentName() }
} else if (!parameters.agentID().isNullOrBlank()) {
agents.firstOrNull { it.id.toString() == parameters.agentID() }
} else if (agents.size == 1) {
agents.first()
} else {
null
}

if (agent == null) {
if (!parameters.agentID().isNullOrBlank()) {
throw IllegalArgumentException("The workspace \"${workspace.name}\" does not have an agent with ID \"${parameters.agentID()}\"")
} else if (!parameters.agentName().isNullOrBlank()) {
if (!parameters.agentName().isNullOrBlank()) {
throw IllegalArgumentException(
"The workspace \"${workspace.name}\"does not have an agent named \"${parameters.agentName()}\"",
"The workspace \"${workspace.name}\" does not have an agent named \"${parameters.agentName()}\"",
)
} else if (!parameters.agentID().isNullOrBlank()) {
throw IllegalArgumentException("The workspace \"${workspace.name}\" does not have an agent with ID \"${parameters.agentID()}\"")
} else {
throw MissingArgumentException(
"Unable to determine which agent to connect to; one of \"$AGENT_NAME\" or \"$AGENT_ID\" must be set because the workspace \"${workspace.name}\" has more than one agent",
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/coder/gateway/util/LinkMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

fun Map<String, String?>.agentName() = this[AGENT_NAME]

@Deprecated("Use the agent name instead")

Check notice on line 32 in src/main/kotlin/com/coder/gateway/util/LinkMap.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

@Deprecated annotation without 'replaceWith' argument

'@deprecated' annotation without a 'replaceWith' argument
fun Map<String, String?>.agentID() = this[AGENT_ID]

fun Map<String, String>.folder() = this[FOLDER]
Expand Down
Loading
Loading