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 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
Next Next commit
make download cli respect header command if one exists
  • Loading branch information
liorb-canva committed Nov 2, 2023
commit 87f51dc4ab8ca3895670a6198232342e90c8dbfb
13 changes: 13 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,11 +101,19 @@ class CoderCLIManager @JvmOverloads constructor(
fun downloadCLI(): Boolean {
val etag = getBinaryETag()
val conn = remoteBinaryURL.openConnection() as HttpURLConnection
if (settings.headerCommand.isNotBlank()){
// get headers
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\"")
}
conn.setRequestProperty("Accept-Encoding", "gzip")

if (conn is HttpsURLConnection) {
conn.sslSocketFactory = coderSocketFactory(settings)
conn.hostnameVerifier = CoderHostnameVerifier(settings.tlsAlternateHostname)
Expand Down Expand Up @@ -172,13 +180,17 @@ class CoderCLIManager @JvmOverloads constructor(
*/
fun login(token: String): String {
logger.info("Storing CLI credentials in $coderConfigPath")
logger.info("Storing CLI credentials in $coderConfigPath")

return exec(
"login",
deploymentURL.toString(),
"--token",
token,
"--global-config",
coderConfigPath.toString(),
"--header-command",
settings.headerCommand
)
}

Expand Down Expand Up @@ -364,6 +376,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