Skip to content

feat: expand ${userHome} in tls settings paths #176

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 1 commit into from
Dec 8, 2023
Merged
Changes from all 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
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAuthenticatedUser } from "coder/site/src/api/api"
import fs from "fs"
import * as https from "https"
import * as module from "module"
import * as os from "os"
import * as vscode from "vscode"
import { Commands } from "./commands"
import { CertificateError } from "./error"
Expand Down Expand Up @@ -31,16 +32,22 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
false,
)

// expandPath will expand ${userHome} in the input string.
const expandPath = (input: string): string => {
const userHome = os.homedir()
return input.replace(/\${userHome}/g, userHome)
}

// applyHttpProperties is called on extension activation and when the
// insecure or TLS setting are changed. It updates the https agent to allow
// self-signed certificates if the insecure setting is true, as well as
// adding cert/key/ca properties for TLS.
const applyHttpProperties = () => {
const cfg = vscode.workspace.getConfiguration()
const insecure = Boolean(cfg.get("coder.insecure"))
const certFile = String(cfg.get("coder.tlsCertFile") ?? "").trim()
const keyFile = String(cfg.get("coder.tlsKeyFile") ?? "").trim()
const caFile = String(cfg.get("coder.tlsCaFile") ?? "").trim()
const certFile = expandPath(String(cfg.get("coder.tlsCertFile") ?? "").trim())
const keyFile = expandPath(String(cfg.get("coder.tlsKeyFile") ?? "").trim())
const caFile = expandPath(String(cfg.get("coder.tlsCaFile") ?? "").trim())

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