Thanks to visit codestin.com
Credit goes to github.com

Skip to content

prevent unintended early return from skipping writing wildcard configs #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make blockContent empty on no workspaces
  • Loading branch information
bcpeinhardt committed Feb 19, 2025
commit 308b9ff71553a0b458adb648b3505a5795408d34
13 changes: 6 additions & 7 deletions src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") {
}
}

private fun validateDataDirectory(): ValidationInfoBuilder.(JBTextField) -> ValidationInfo? =
{
if (it.text.isNotBlank() && !Path.of(it.text).canCreateDirectory()) {
error("Cannot create this directory")
} else {
null
}
private fun validateDataDirectory(): ValidationInfoBuilder.(JBTextField) -> ValidationInfo? = {
if (it.text.isNotBlank() && !Path.of(it.text).canCreateDirectory()) {
error("Cannot create this directory")
} else {
null
}
}
}
94 changes: 45 additions & 49 deletions src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,35 +307,36 @@ class CoderCLIManager(
Host ${getHostPrefix()}-bg--*
ProxyCommand ${backgroundProxyArgs.joinToString(" ")} --ssh-host-prefix ${getHostPrefix()}-bg-- %h
""".trimIndent()
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig),
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig),
).replace("\n", System.lineSeparator()) +
System.lineSeparator() + endBlock

} else {
workspaceNames.joinToString(
System.lineSeparator(),
startBlock + System.lineSeparator(),
System.lineSeparator() + endBlock,
transform = {
"""
} else if (workspaceNames.isEmpty()) {
""
} else {
workspaceNames.joinToString(
System.lineSeparator(),
startBlock + System.lineSeparator(),
System.lineSeparator() + endBlock,
transform = {
"""
Host ${getHostName(it.first, currentUser, it.second)}
ProxyCommand ${proxyArgs.joinToString(" ")} ${getWorkspaceParts(it.first, it.second)}
""".trimIndent()
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig)
.plus("\n")
.plus(
"""
""".trimIndent()
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig)
.plus("\n")
.plus(
"""
Host ${getBackgroundHostName(it.first, currentUser, it.second)}
ProxyCommand ${backgroundProxyArgs.joinToString(" ")} ${getWorkspaceParts(it.first, it.second)}
""".trimIndent()
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig),
).replace("\n", System.lineSeparator())
},
)
}
""".trimIndent()
.plus("\n" + sshOpts.prependIndent(" "))
.plus(extraConfig),
).replace("\n", System.lineSeparator())
},
)
}

if (contents == null) {
logger.info("No existing SSH config to modify")
Expand Down Expand Up @@ -478,15 +479,13 @@ class CoderCLIManager(
*
* Throws if the command execution fails.
*/
fun startWorkspace(workspaceOwner: String, workspaceName: String): String {
return exec(
"--global-config",
coderConfigPath.toString(),
"start",
"--yes",
workspaceOwner+"/"+workspaceName,
)
}
fun startWorkspace(workspaceOwner: String, workspaceName: String): String = exec(
"--global-config",
coderConfigPath.toString(),
"start",
"--yes",
workspaceOwner + "/" + workspaceName,
)

private fun exec(vararg args: String): String {
val stdout =
Expand Down Expand Up @@ -519,8 +518,7 @@ class CoderCLIManager(
/*
* This function returns the ssh-host-prefix used for Host entries.
*/
fun getHostPrefix(): String =
"coder-jetbrains-${deploymentURL.safeHost()}"
fun getHostPrefix(): String = "coder-jetbrains-${deploymentURL.safeHost()}"

/**
* This function returns the ssh host name generated for connecting to the workspace.
Expand All @@ -529,29 +527,27 @@ class CoderCLIManager(
workspace: Workspace,
currentUser: User,
agent: WorkspaceAgent,
): String =
if (features.wildcardSSH) {
"${getHostPrefix()}--${workspace.ownerName}--${workspace.name}.${agent.name}"
): String = if (features.wildcardSSH) {
"${getHostPrefix()}--${workspace.ownerName}--${workspace.name}.${agent.name}"
} else {
// For a user's own workspace, we use the old syntax without a username for backwards compatibility,
// since the user might have recent connections that still use the old syntax.
if (currentUser.username == workspace.ownerName) {
"coder-jetbrains--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
} else {
// For a user's own workspace, we use the old syntax without a username for backwards compatibility,
// since the user might have recent connections that still use the old syntax.
if (currentUser.username == workspace.ownerName) {
"coder-jetbrains--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
} else {
"coder-jetbrains--${workspace.ownerName}--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
"coder-jetbrains--${workspace.ownerName}--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
}
}

fun getBackgroundHostName(
workspace: Workspace,
currentUser: User,
agent: WorkspaceAgent,
): String =
if (features.wildcardSSH) {
"${getHostPrefix()}-bg--${workspace.ownerName}--${workspace.name}.${agent.name}"
} else {
getHostName(workspace, currentUser, agent) + "--bg"
}
): String = if (features.wildcardSSH) {
"${getHostPrefix()}-bg--${workspace.ownerName}--${workspace.name}.${agent.name}"
} else {
getHostName(workspace, currentUser, agent) + "--bg"
}

companion object {
val logger = Logger.getInstance(CoderCLIManager::class.java.simpleName)
Expand Down
83 changes: 41 additions & 42 deletions src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,47 @@ object CoderIcons {
private val Y = IconLoader.getIcon("symbols/y.svg", javaClass)
private val Z = IconLoader.getIcon("symbols/z.svg", javaClass)

fun fromChar(c: Char) =
when (c) {
'0' -> ZERO
'1' -> ONE
'2' -> TWO
'3' -> THREE
'4' -> FOUR
'5' -> FIVE
'6' -> SIX
'7' -> SEVEN
'8' -> EIGHT
'9' -> NINE

'a' -> A
'b' -> B
'c' -> C
'd' -> D
'e' -> E
'f' -> F
'g' -> G
'h' -> H
'i' -> I
'j' -> J
'k' -> K
'l' -> L
'm' -> M
'n' -> N
'o' -> O
'p' -> P
'q' -> Q
'r' -> R
's' -> S
't' -> T
'u' -> U
'v' -> V
'w' -> W
'x' -> X
'y' -> Y
'z' -> Z

else -> UNKNOWN
}
fun fromChar(c: Char) = when (c) {
'0' -> ZERO
'1' -> ONE
'2' -> TWO
'3' -> THREE
'4' -> FOUR
'5' -> FIVE
'6' -> SIX
'7' -> SEVEN
'8' -> EIGHT
'9' -> NINE

'a' -> A
'b' -> B
'c' -> C
'd' -> D
'e' -> E
'f' -> F
'g' -> G
'h' -> H
'i' -> I
'j' -> J
'k' -> K
'l' -> L
'm' -> M
'n' -> N
'o' -> O
'p' -> P
'q' -> Q
'r' -> R
's' -> S
't' -> T
'u' -> U
'v' -> V
'w' -> W
'x' -> X
'y' -> Y
'z' -> Z

else -> UNKNOWN
}
}

fun alignToInt(g: Graphics) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
READY("Ready", "The agent is ready to accept connections."),
;

fun statusColor(): JBColor =
when (this) {
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
}
fun statusColor(): JBColor = when (this) {
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
}

/**
* Return true if the agent is in a connectable state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import java.time.temporal.TemporalAccessor
class InstantConverter {
@ToJson fun toJson(src: Instant?): String = FORMATTER.format(src)

@FromJson fun fromJson(src: String): Instant? =
FORMATTER.parse(src) { temporal: TemporalAccessor? ->
Instant.from(temporal)
}
@FromJson fun fromJson(src: String): Instant? = FORMATTER.parse(src) { temporal: TemporalAccessor? ->
Instant.from(temporal)
}

companion object {
private val FORMATTER = DateTimeFormatter.ISO_INSTANT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ open class CoderSettings(
* Whether to check for IDE updates.
*/
val checkIDEUpdate: Boolean
get() = state.checkIDEUpdates
get() = state.checkIDEUpdates

/**
* Whether to ignore a failed setup command.
Expand Down
Loading