Skip to content

Commit a6e43e9

Browse files
authored
Add option to disable downloads (#263)
1 parent 0bf09b9 commit a6e43e9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
"type": "string",
6464
"default": ""
6565
},
66+
"coder.enableDownloads": {
67+
"markdownDescription": "Allow the plugin to download the CLI when missing or out of date.",
68+
"type": "boolean",
69+
"default": true
70+
},
6671
"coder.headerCommand": {
6772
"markdownDescription": "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`. Defaults to the value of `CODER_HEADER_COMMAND` if not set.",
6873
"type": "string",

src/storage.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export class Storage {
121121
/**
122122
* Download and return the path to a working binary. If there is already a
123123
* working binary and it matches the server version, return that, skipping the
124-
* download. Throw if unable to download a working binary.
124+
* download. If it does not match but downloads are disabled, return whatever
125+
* we have and log a warning. Otherwise throw if unable to download a working
126+
* binary, whether because of network issues or downloads being disabled.
125127
*/
126128
public async fetchBinary(): Promise<string> {
127129
const baseURL = this.getURL()
@@ -130,13 +132,19 @@ export class Storage {
130132
}
131133
this.output.appendLine(`Using deployment URL: ${baseURL}`)
132134

135+
// Settings can be undefined when set to their defaults (true in this case),
136+
// so explicitly check against false.
137+
const enableDownloads = vscode.workspace.getConfiguration().get("coder.enableDownloads") !== false
138+
this.output.appendLine(`Downloads are ${enableDownloads ? "enabled" : "disabled"}`)
139+
133140
// Get the build info to compare with the existing binary version, if any,
134141
// and to log for debugging.
135142
const buildInfo = await getBuildInfo()
136143
this.output.appendLine(`Got server version: ${buildInfo.version}`)
137144

138145
// Check if there is an existing binary and whether it looks valid. If it
139-
// is valid and matches the server, we can return early.
146+
// is valid and matches the server, or if it does not match the server but
147+
// downloads are disabled, we can return early.
140148
const binPath = this.binaryPath()
141149
this.output.appendLine(`Using binary path: ${binPath}`)
142150
const stat = await cli.stat(binPath)
@@ -151,6 +159,11 @@ export class Storage {
151159
if (version === buildInfo.version) {
152160
this.output.appendLine("Using existing binary since it matches the server version")
153161
return binPath
162+
} else if (!enableDownloads) {
163+
this.output.appendLine(
164+
"Using existing binary even though it does not match the server version because downloads are disabled",
165+
)
166+
return binPath
154167
}
155168
this.output.appendLine("Downloading since existing binary does not match the server version")
156169
} catch (error) {
@@ -159,6 +172,11 @@ export class Storage {
159172
}
160173
}
161174

175+
if (!enableDownloads) {
176+
this.output.appendLine("Unable to download CLI because downloads are disabled")
177+
throw new Error("Unable to download CLI because downloads are disabled")
178+
}
179+
162180
// Remove any left-over old or temporary binaries.
163181
const removed = await cli.rmOld(binPath)
164182
removed.forEach(({ fileName, error }) => {

0 commit comments

Comments
 (0)