Skip to content

Commit 6ddf339

Browse files
committed
initial work making logDir optional
1 parent b35779a commit 6ddf339

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
"type": "string",
8989
"default": ""
9090
},
91+
"coder.proxyLogDirectory": {
92+
"markdownDescription": "If set, the Coder CLI will output extra SSH information into this directory, which can be helpful for debugging connectivity issues.",
93+
"type": "string",
94+
"default": ""
95+
},
9196
"coder.proxyBypass": {
9297
"markdownDescription": "If not set, will inherit from the `no_proxy` or `NO_PROXY` environment variables. `http.proxySupport` must be set to `on` or `off`, otherwise VS Code will override the proxy agent set by the plugin.",
9398
"type": "string",

src/api.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ import { errToStr } from "./api-helper"
99
import { CertificateError } from "./error"
1010
import { getProxyForUrl } from "./proxy"
1111
import { Storage } from "./storage"
12-
13-
// expandPath will expand ${userHome} in the input string.
14-
function expandPath(input: string): string {
15-
const userHome = os.homedir()
16-
return input.replace(/\${userHome}/g, userHome)
17-
}
12+
import { expandPath } from "./util"
1813

1914
async function createHttpAgent(): Promise<ProxyAgent> {
2015
const cfg = vscode.workspace.getConfiguration()

src/error.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function startServer(certName: string): Promise<string> {
5252
disposers.push(() => server.close())
5353
return new Promise<string>((resolve, reject) => {
5454
server.on("error", reject)
55-
server.listen(0, "localhost", () => {
55+
server.listen(0, "127.0.0.1", () => {
5656
const address = server.address()
5757
if (!address) {
5858
throw new Error("Server has no address")

src/remote.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getHeaderCommand } from "./headers"
1717
import { SSHConfig, SSHValues, mergeSSHConfigValues } from "./sshConfig"
1818
import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport"
1919
import { Storage } from "./storage"
20-
import { AuthorityPrefix, parseRemoteAuthority } from "./util"
20+
import { AuthorityPrefix, expandPath, parseRemoteAuthority } from "./util"
2121
import { supportsCoderAgentLogDirFlag } from "./version"
2222
import { WorkspaceAction } from "./workspaceAction"
2323

@@ -33,6 +33,7 @@ export class Remote {
3333
private readonly storage: Storage,
3434
private readonly commands: Commands,
3535
private readonly mode: vscode.ExtensionMode,
36+
private coderVersion: semver.SemVer | null = null
3637
) {}
3738

3839
private async confirmStart(workspaceName: string): Promise<boolean> {
@@ -195,13 +196,13 @@ export class Remote {
195196

196197
// First thing is to check the version.
197198
const buildInfo = await workspaceRestClient.getBuildInfo()
198-
const parsedVersion = semver.parse(buildInfo.version)
199+
this.coderVersion = semver.parse(buildInfo.version)
199200
// Server versions before v0.14.1 don't support the vscodessh command!
200201
if (
201-
parsedVersion?.major === 0 &&
202-
parsedVersion?.minor <= 14 &&
203-
parsedVersion?.patch < 1 &&
204-
parsedVersion?.prerelease.length === 0
202+
this.coderVersion?.major === 0 &&
203+
this.coderVersion?.minor <= 14 &&
204+
this.coderVersion?.patch < 1 &&
205+
this.coderVersion?.prerelease.length === 0
205206
) {
206207
await this.vscodeProposed.window.showErrorMessage(
207208
"Incompatible Server",
@@ -215,7 +216,6 @@ export class Remote {
215216
await this.closeRemote()
216217
return
217218
}
218-
const hasCoderLogs = supportsCoderAgentLogDirFlag(parsedVersion)
219219

220220
// Next is to find the workspace from the URI scheme provided.
221221
let workspace: Workspace
@@ -501,7 +501,7 @@ export class Remote {
501501
// "Host not found".
502502
try {
503503
this.storage.writeToCoderOutputChannel("Updating SSH config...")
504-
await this.updateSSHConfig(workspaceRestClient, parts.label, parts.host, hasCoderLogs)
504+
await this.updateSSHConfig(workspaceRestClient, parts.label, parts.host)
505505
} catch (error) {
506506
this.storage.writeToCoderOutputChannel(`Failed to configure SSH: ${error}`)
507507
throw error
@@ -543,7 +543,7 @@ export class Remote {
543543

544544
// updateSSHConfig updates the SSH configuration with a wildcard that handles
545545
// all Coder entries.
546-
private async updateSSHConfig(restClient: Api, label: string, hostName: string, hasCoderLogs = false) {
546+
private async updateSSHConfig(restClient: Api, label: string, hostName: string) {
547547
let deploymentSSHConfig = {}
548548
try {
549549
const deploymentConfig = await restClient.getDeploymentSSHConfig()
@@ -635,9 +635,13 @@ export class Remote {
635635
headerArg = ` --header-command ${escapeSubcommand(headerCommand)}`
636636
}
637637
let logArg = ""
638-
if (hasCoderLogs) {
639-
await fs.mkdir(this.storage.getLogPath(), { recursive: true })
640-
logArg = ` --log-dir ${escape(this.storage.getLogPath())}`
638+
if (supportsCoderAgentLogDirFlag(this.coderVersion)) {
639+
const logDir = expandPath(String(vscode.workspace.getConfiguration().get("coder.proxyLogDirectory") ?? "").trim())
640+
if (logDir) {
641+
await fs.mkdir(this.storage.getLogPath(), { recursive: true })
642+
logArg = ` --log-dir ${escape(this.storage.getLogPath())}`
643+
this.storage.writeToCoderOutputChannel(`Your logs are being written to ${this.storage.getLogPath()}`)
644+
}
641645
}
642646
const sshValues: SSHValues = {
643647
Host: label ? `${AuthorityPrefix}.${label}--*` : `${AuthorityPrefix}--*`,

src/util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import url from "url"
2+
import * as os from "os"
23

34
export interface AuthorityParts {
45
agent: string | undefined
@@ -58,3 +59,13 @@ export function toSafeHost(rawUrl: string): string {
5859
// should already have thrown in that case.
5960
return url.domainToASCII(u.hostname) || u.hostname
6061
}
62+
63+
/**
64+
* Expand a path with ${userHome} in the input string
65+
* @param input string
66+
* @returns string
67+
*/
68+
export function expandPath(input: string): string {
69+
const userHome = os.homedir()
70+
return input.replace(/\${userHome}/g, userHome)
71+
}

0 commit comments

Comments
 (0)