Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## Unreleased

### Added

- the header command falls back to the `CODER_HEADER_COMMAND` environment variable when the setting is blank, matching the Coder CLI and the VS Code extension

## 2.23.1 - 2026-01-21

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.coder.gateway

import com.coder.gateway.services.CoderSettingsService
import com.coder.gateway.services.CoderSettingsStateService
import com.coder.gateway.settings.CODER_HEADER_COMMAND
import com.coder.gateway.settings.CODER_SSH_CONFIG_OPTIONS
import com.coder.gateway.util.canCreateDirectory
import com.intellij.openapi.components.service
Expand Down Expand Up @@ -89,7 +90,10 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") {
textField().resizableColumn().align(AlignX.FILL)
.bindText(state::headerCommand)
.comment(
CoderGatewayBundle.message("gateway.connector.settings.header-command.comment"),
CoderGatewayBundle.message(
"gateway.connector.settings.header-command.comment",
CODER_HEADER_COMMAND,
),
)
}.layout(RowLayout.PARENT_GRID)
row(CoderGatewayBundle.message("gateway.connector.settings.tls-cert-path.title")) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

const val CODER_HEADER_COMMAND = "CODER_HEADER_COMMAND"
const val CODER_SSH_CONFIG_OPTIONS = "CODER_SSH_CONFIG_OPTIONS"
const val CODER_URL = "CODER_URL"

Expand Down Expand Up @@ -76,8 +77,8 @@ open class CoderSettingsState(

// An external command that outputs additional HTTP headers added to all
// requests. The command must output each header as `key=value` on its own
// line. The following environment variables will be available to the
// process: CODER_URL.
// line. When this setting is blank, the CODER_HEADER_COMMAND environment
// variable is used instead, if set.
open var headerCommand: String = "",
// Optionally set this to the path of a certificate to use for TLS
// connections. The certificate should be in X.509 PEM format.
Expand Down Expand Up @@ -194,10 +195,12 @@ open class CoderSettings(
val defaultSignatureNameByOsAndArch: String get() = getCoderSignatureForOS(getOS(), getArch())

/**
* A command to run to set headers for API calls.
* A command to run to set headers for API calls. Falls back to the
* CODER_HEADER_COMMAND environment variable (the same variable the Coder
* CLI reads) when the setting is blank.
*/
val headerCommand: String
get() = state.headerCommand
get() = state.headerCommand.ifBlank { env.get(CODER_HEADER_COMMAND) }

/**
* Whether to disable automatically starting a workspace when connecting.
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages/CoderGatewayBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ gateway.connector.settings.fallback-on-coder-for-signatures.comment=Verify binar
gateway.connector.settings.header-command.title=Header command
gateway.connector.settings.header-command.comment=An external command that \
outputs additional HTTP headers added to all requests. The command must \
output each header as `key=value` on its own line. The following \
environment variables will be available to the process: CODER_URL.
output each header as `key=value` on its own line. When this setting is \
left blank, the environment variable {0} is used instead, if set.
gateway.connector.settings.tls-cert-path.title=Cert path
gateway.connector.settings.tls-cert-path.comment=Optionally set this to \
the path of a certificate to use for TLS connections. The certificate \
Expand Down
21 changes: 21 additions & 0 deletions src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,27 @@ internal class CoderSettingsTest {
assertEquals(Pair("http://test.gateway.coder.com$expected", null), got)
}

@Test
fun testHeaderCommand() {
var settings = CoderSettings(CoderSettingsState(headerCommand = "header command from state"))
assertEquals("header command from state", settings.headerCommand)

settings =
CoderSettings(
CoderSettingsState(),
env = Environment(mapOf(CODER_HEADER_COMMAND to "header command from env")),
)
assertEquals("header command from env", settings.headerCommand)

// State has precedence.
settings =
CoderSettings(
CoderSettingsState(headerCommand = "header command from state"),
env = Environment(mapOf(CODER_HEADER_COMMAND to "header command from env")),
)
assertEquals("header command from state", settings.headerCommand)
}

@Test
fun testSSHConfigOptions() {
var settings = CoderSettings(CoderSettingsState(sshConfigOptions = "ssh config options from state"))
Expand Down