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
feat: expand ${userHome} in tls settings paths
For parity with the jetbrains-coder plugin allow for HOME directory
expansion in the path locations for tls configuration settings.  Using
the `${userHome}` variable as this is used in other VSCode
configurations like launch.json.
  • Loading branch information
coryb committed Dec 6, 2023
commit a567fc3e4491f86e53c6e65b1d04a6177ea6c00c
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