-
Notifications
You must be signed in to change notification settings - Fork 16
Add the ability to disable autostart #366
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,9 +199,11 @@ class CoderCLIManager( | |
|
||
/** | ||
* Configure SSH to use this binary. | ||
* | ||
* This can take a version for testing purposes only. | ||
*/ | ||
fun configSsh(workspaceNames: List<String>) { | ||
writeSSHConfig(modifySSHConfig(readSSHConfig(), workspaceNames)) | ||
fun configSsh(workspaceNames: List<String>, version: SemVer? = tryVersion()) { | ||
writeSSHConfig(modifySSHConfig(readSSHConfig(), workspaceNames, version)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: refactor to
This allows you to then simplify the logic in line 235 to
and move the version checking logic outside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of something like this! But then it felt weird because sometimes we would use the settings (for header command) and sometimes not (for disable autostart). Maybe a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, that would definitely make things more confusing. Not a blocker for me in any case. |
||
} | ||
|
||
/** | ||
|
@@ -220,7 +222,7 @@ class CoderCLIManager( | |
* this deployment and return the modified config or null if it does not | ||
* need to be modified. | ||
*/ | ||
private fun modifySSHConfig(contents: String?, workspaceNames: List<String>): String? { | ||
private fun modifySSHConfig(contents: String?, workspaceNames: List<String>, version: SemVer?): String? { | ||
val host = deploymentURL.safeHost() | ||
val startBlock = "# --- START CODER JETBRAINS $host" | ||
val endBlock = "# --- END CODER JETBRAINS $host" | ||
|
@@ -230,15 +232,17 @@ class CoderCLIManager( | |
"--global-config", escape(coderConfigPath.toString()), | ||
if (settings.headerCommand.isNotBlank()) "--header-command" else null, | ||
if (settings.headerCommand.isNotBlank()) escapeSubcommand(settings.headerCommand) else null, | ||
"ssh", "--stdio") | ||
"ssh", "--stdio", | ||
// Autostart on SSH was added in 2.5.0. | ||
if (settings.disableAutostart && version != null && version >= SemVer(2, 5, 0)) "--disable-autostart" else null) | ||
val blockContent = workspaceNames.joinToString( | ||
System.lineSeparator(), | ||
startBlock + System.lineSeparator(), | ||
System.lineSeparator() + endBlock, | ||
transform = { | ||
""" | ||
Host ${getHostName(deploymentURL, it)} | ||
ProxyCommand ${proxyArgs.joinToString(" ")} ${it} | ||
ProxyCommand ${proxyArgs.joinToString(" ")} $it | ||
ConnectTimeout 0 | ||
StrictHostKeyChecking no | ||
UserKnownHostsFile /dev/null | ||
|
@@ -333,31 +337,36 @@ class CoderCLIManager( | |
} | ||
|
||
/** | ||
* Returns true if the CLI has the same major/minor/patch version as the | ||
* provided version, false if it does not match, or null if the CLI version | ||
* could not be determined because the binary could not be executed or the | ||
* version could not be parsed. | ||
* Like version(), but logs errors instead of throwing them. | ||
*/ | ||
fun matchesVersion(rawBuildVersion: String): Boolean? { | ||
val cliVersion = try { | ||
private fun tryVersion(): SemVer? { | ||
return try { | ||
version() | ||
} catch (e: Exception) { | ||
when (e) { | ||
is JsonSyntaxException, | ||
is InvalidVersionException -> { | ||
logger.info("Got invalid version from $localBinaryPath: ${e.message}") | ||
return null | ||
} | ||
else -> { | ||
// An error here most likely means the CLI does not exist or | ||
// it executed successfully but output no version which | ||
// suggests it is not the right binary. | ||
logger.info("Unable to determine $localBinaryPath version: ${e.message}") | ||
return null | ||
} | ||
} | ||
null | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the CLI has the same major/minor/patch version as the | ||
* provided version, false if it does not match, or null if the CLI version | ||
* could not be determined because the binary could not be executed or the | ||
* version could not be parsed. | ||
*/ | ||
fun matchesVersion(rawBuildVersion: String): Boolean? { | ||
val cliVersion = tryVersion() ?: return null | ||
val buildVersion = try { | ||
SemVer.parse(rawBuildVersion) | ||
} catch (e: InvalidVersionException) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# --- START CODER JETBRAINS test.coder.invalid | ||
Host coder-jetbrains--foo--test.coder.invalid | ||
ProxyCommand /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64 --global-config /tmp/coder-gateway/test.coder.invalid/config ssh --stdio --disable-autostart foo | ||
ConnectTimeout 0 | ||
StrictHostKeyChecking no | ||
UserKnownHostsFile /dev/null | ||
LogLevel ERROR | ||
SetEnv CODER_SSH_SESSION_TYPE=JetBrains | ||
# --- END CODER JETBRAINS test.coder.invalid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# --- START CODER JETBRAINS test.coder.invalid | ||
Host coder-jetbrains--foo--test.coder.invalid | ||
ProxyCommand /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64 --global-config /tmp/coder-gateway/test.coder.invalid/config ssh --stdio foo | ||
ConnectTimeout 0 | ||
StrictHostKeyChecking no | ||
UserKnownHostsFile /dev/null | ||
LogLevel ERROR | ||
SetEnv CODER_SSH_SESSION_TYPE=JetBrains | ||
# --- END CODER JETBRAINS test.coder.invalid |
Uh oh!
There was an error while loading. Please reload this page.