@@ -4,6 +4,7 @@ import { getAuthenticatedUser } from "coder/site/src/api/api"
4
4
import fs from "fs"
5
5
import * as https from "https"
6
6
import * as module from "module"
7
+ import * as os from "os"
7
8
import * as vscode from "vscode"
8
9
import { Commands } from "./commands"
9
10
import { CertificateError } from "./error"
@@ -31,16 +32,22 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
31
32
false ,
32
33
)
33
34
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
+
34
41
// applyHttpProperties is called on extension activation and when the
35
42
// insecure or TLS setting are changed. It updates the https agent to allow
36
43
// self-signed certificates if the insecure setting is true, as well as
37
44
// adding cert/key/ca properties for TLS.
38
45
const applyHttpProperties = ( ) => {
39
46
const cfg = vscode . workspace . getConfiguration ( )
40
47
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 ( ) )
44
51
45
52
axios . defaults . httpsAgent = new https . Agent ( {
46
53
cert : certFile === "" ? undefined : fs . readFileSync ( certFile ) ,
0 commit comments