Skip to content

Adding Header Commands To The Download CLI phase #323

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 6 commits into from
Nov 2, 2023
Merged
Changes from 3 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
9 changes: 9 additions & 0 deletions src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class CoderCLIManager @JvmOverloads constructor(
fun downloadCLI(): Boolean {
val etag = getBinaryETag()
val conn = remoteBinaryURL.openConnection() as HttpURLConnection
if (settings.headerCommand.isNotBlank()){
val headersFromHeaderCommand =CoderRestClient.getHeaders(deploymentURL,settings.headerCommand)
for ((key, value) in headersFromHeaderCommand) {
conn.setRequestProperty(key, value)
}
}
if (etag != null) {
logger.info("Found existing binary at $localBinaryPath; calculated hash as $etag")
conn.setRequestProperty("If-None-Match", "\"$etag\"")
Expand Down Expand Up @@ -179,6 +185,8 @@ class CoderCLIManager @JvmOverloads constructor(
token,
"--global-config",
coderConfigPath.toString(),
"--header-command",
settings.headerCommand
)
}

Expand Down Expand Up @@ -364,6 +372,7 @@ class CoderCLIManager @JvmOverloads constructor(
private fun exec(vararg args: String): String {
val stdout = ProcessExecutor()
.command(localBinaryPath.toString(), *args)
.environment("CODER_HEADER_COMMAND",settings.headerCommand)
.exitValues(0)
.readOutput(true)
.execute()
Expand Down