Skip to content

Commit ea02218

Browse files
authored
feat: expand ${userHome} in tls settings paths (#176)
1 parent c318bcc commit ea02218

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/extension.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getAuthenticatedUser } from "coder/site/src/api/api"
44
import fs from "fs"
55
import * as https from "https"
66
import * as module from "module"
7+
import * as os from "os"
78
import * as vscode from "vscode"
89
import { Commands } from "./commands"
910
import { CertificateError } from "./error"
@@ -31,16 +32,22 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
3132
false,
3233
)
3334

35+
// expandPath will expand ${userHome} in the input string.
36+
const expandPath = (input: string): string => {
37+
const userHome = os.homedir()
38+
return input.replace(/\${userHome}/g, userHome)
39+
}
40+
3441
// applyHttpProperties is called on extension activation and when the
3542
// insecure or TLS setting are changed. It updates the https agent to allow
3643
// self-signed certificates if the insecure setting is true, as well as
3744
// adding cert/key/ca properties for TLS.
3845
const applyHttpProperties = () => {
3946
const cfg = vscode.workspace.getConfiguration()
4047
const insecure = Boolean(cfg.get("coder.insecure"))
41-
const certFile = String(cfg.get("coder.tlsCertFile") ?? "").trim()
42-
const keyFile = String(cfg.get("coder.tlsKeyFile") ?? "").trim()
43-
const caFile = String(cfg.get("coder.tlsCaFile") ?? "").trim()
48+
const certFile = expandPath(String(cfg.get("coder.tlsCertFile") ?? "").trim())
49+
const keyFile = expandPath(String(cfg.get("coder.tlsKeyFile") ?? "").trim())
50+
const caFile = expandPath(String(cfg.get("coder.tlsCaFile") ?? "").trim())
4451

4552
axios.defaults.httpsAgent = new https.Agent({
4653
cert: certFile === "" ? undefined : fs.readFileSync(certFile),

0 commit comments

Comments
 (0)