Skip to content

Commit 8193a11

Browse files
authored
Add binary source and destination settings (#122)
1 parent 7cec304 commit 8193a11

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
"markdownDescription": "If true, the extension will not verify the authenticity of the remote host. This is useful for self-signed certificates.",
4848
"type": "boolean",
4949
"default": false
50+
},
51+
"coder.binarySource": {
52+
"markdownDescription": "Used to download the Coder CLI which is necessary to make SSH connections. The If-None-Match header will be set to the SHA1 of the CLI and can be used for caching. Absolute URLs will be used as-is; otherwise this value will be resolved against the deployment domain. Defaults to downloading from the Coder deployment.",
53+
"type": "string",
54+
"default": ""
55+
},
56+
"coder.binaryDestination": {
57+
"markdownDescription": "The full path of the directory into which the Coder CLI will be downloaded. Defaults to the extension's global storage directory.",
58+
"type": "string",
59+
"default": ""
5060
}
5161
}
5262
},
@@ -233,7 +243,7 @@
233243
"dependencies": {
234244
"@types/node-forge": "^1.3.4",
235245
"@types/ua-parser-js": "^0.7.36",
236-
"axios": "0.26.1",
246+
"axios": "1.4.0",
237247
"date-fns": "^2.30.0",
238248
"eventsource": "^2.0.2",
239249
"find-process": "^1.4.7",

src/error.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ it("falls back with different error", async () => {
219219
} catch (error) {
220220
const wrapped = await CertificateError.maybeWrap(error, "1", logger)
221221
expect(wrapped instanceof CertificateError).toBeFalsy()
222-
expect(wrapped.message).toMatch(/failed with status code 500/)
222+
expect((wrapped as Error).message).toMatch(/failed with status code 500/)
223223
}
224224
})

src/storage.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export class Storage {
8888
if (!baseURL) {
8989
throw new Error("Must be logged in!")
9090
}
91-
const baseURI = vscode.Uri.parse(baseURL)
9291

9392
const buildInfo = await getBuildInfo()
9493
const binPath = this.binaryPath()
@@ -117,11 +116,16 @@ export class Storage {
117116
if (exists) {
118117
etag = await this.getBinaryETag()
119118
}
119+
120+
const configSource = vscode.workspace.getConfiguration().get("coder.binarySource")
121+
const binSource = configSource && String(configSource).trim().length > 0 ? String(configSource) : "/bin/" + binName
122+
120123
this.output.appendLine(`Using binName: ${binName}`)
121124
this.output.appendLine(`Using binPath: ${binPath}`)
125+
this.output.appendLine(`Using binSource: ${binSource}`)
122126
this.output.appendLine(`Using ETag: ${etag}`)
123127

124-
const resp = await axios.get("/bin/" + binName, {
128+
const resp = await axios.get(binSource, {
125129
signal: controller.signal,
126130
baseURL: baseURL,
127131
responseType: "stream",
@@ -146,7 +150,9 @@ export class Storage {
146150
const completed = await vscode.window.withProgress<boolean>(
147151
{
148152
location: vscode.ProgressLocation.Notification,
149-
title: `Downloading the latest binary (${buildInfo.version} from ${baseURI.authority})`,
153+
title: `Downloading the latest binary (${buildInfo.version} from ${axios.getUri(
154+
resp.config,
155+
)}) to ${binPath}`,
150156
cancellable: true,
151157
},
152158
async (progress, token) => {
@@ -260,7 +266,10 @@ export class Storage {
260266
// getBinaryCachePath returns the path where binaries are cached.
261267
// The caller must ensure it exists before use.
262268
public getBinaryCachePath(): string {
263-
return path.join(this.globalStorageUri.fsPath, "bin")
269+
const configPath = vscode.workspace.getConfiguration().get("coder.binaryDestination")
270+
return configPath && String(configPath).trim().length > 0
271+
? path.resolve(String(configPath))
272+
: path.join(this.globalStorageUri.fsPath, "bin")
264273
}
265274

266275
// getNetworkInfoPath returns the path where network information

yarn.lock

+40-7
Original file line numberDiff line numberDiff line change
@@ -1110,17 +1110,24 @@ astral-regex@^2.0.0:
11101110
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
11111111
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==
11121112

1113+
asynckit@^0.4.0:
1114+
version "0.4.0"
1115+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
1116+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
1117+
11131118
available-typed-arrays@^1.0.5:
11141119
version "1.0.5"
11151120
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
11161121
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
11171122

1118-
axios@0.26.1:
1119-
version "0.26.1"
1120-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
1121-
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
1123+
axios@1.4.0:
1124+
version "1.4.0"
1125+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
1126+
integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==
11221127
dependencies:
1123-
follow-redirects "^1.14.8"
1128+
follow-redirects "^1.15.0"
1129+
form-data "^4.0.0"
1130+
proxy-from-env "^1.1.0"
11241131

11251132
azure-devops-node-api@^11.0.1:
11261133
version "11.2.0"
@@ -1473,6 +1480,13 @@ colorette@^2.0.14:
14731480
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
14741481
integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==
14751482

1483+
combined-stream@^1.0.8:
1484+
version "1.0.8"
1485+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
1486+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
1487+
dependencies:
1488+
delayed-stream "~1.0.0"
1489+
14761490
commander@^2.20.0:
14771491
version "2.20.3"
14781492
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
@@ -1619,6 +1633,11 @@ define-properties@^1.1.3, define-properties@^1.1.4:
16191633
has-property-descriptors "^1.0.0"
16201634
object-keys "^1.1.1"
16211635

1636+
delayed-stream@~1.0.0:
1637+
version "1.0.0"
1638+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
1639+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
1640+
16221641
detect-libc@^2.0.0:
16231642
version "2.0.1"
16241643
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.1.tgz#e1897aa88fa6ad197862937fbc0441ef352ee0cd"
@@ -2319,7 +2338,7 @@ flatted@^3.1.0:
23192338
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
23202339
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
23212340

2322-
follow-redirects@^1.14.8:
2341+
follow-redirects@^1.15.0:
23232342
version "1.15.2"
23242343
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
23252344
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
@@ -2339,6 +2358,15 @@ foreground-child@^2.0.0:
23392358
cross-spawn "^7.0.0"
23402359
signal-exit "^3.0.2"
23412360

2361+
form-data@^4.0.0:
2362+
version "4.0.0"
2363+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
2364+
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
2365+
dependencies:
2366+
asynckit "^0.4.0"
2367+
combined-stream "^1.0.8"
2368+
mime-types "^2.1.12"
2369+
23422370
format@^0.2.0:
23432371
version "0.2.2"
23442372
resolved "https://registry.yarnpkg.com/format/-/format-0.2.2.tgz#d6170107e9efdc4ed30c9dc39016df942b5cb58b"
@@ -3311,7 +3339,7 @@ mime-db@1.52.0:
33113339
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
33123340
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
33133341

3314-
mime-types@^2.1.27:
3342+
mime-types@^2.1.12, mime-types@^2.1.27:
33153343
version "2.1.35"
33163344
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
33173345
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
@@ -3823,6 +3851,11 @@ progress@^2.0.0:
38233851
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
38243852
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
38253853

3854+
proxy-from-env@^1.1.0:
3855+
version "1.1.0"
3856+
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
3857+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
3858+
38263859
prr@~1.0.1:
38273860
version "1.0.1"
38283861
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"

0 commit comments

Comments
 (0)