Skip to content

feat: coder connect integration #482

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

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
support stopped workspaces
  • Loading branch information
ethanndickson committed Apr 17, 2025
commit 2ecf1dff733b05c7aeec99d3f830e6e8b8bc5292
59 changes: 28 additions & 31 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,13 @@ export class Commands {
throw new Error("You are not logged in")
}

const agent = treeItem.workspaceAgent
if (!agent) {
// `openFromSidebar` is only callable on agents or single-agent workspaces,
// where this will always be set.
return
}

try {
await openWorkspace(
this.restClient,
baseUrl,
treeItem.workspaceOwner,
treeItem.workspaceName,
agent,
treeItem.workspaceAgent,
treeItem.workspaceFolderPath,
true,
)
Expand Down Expand Up @@ -592,37 +585,41 @@ async function openWorkspace(
baseUrl: string,
workspaceOwner: string,
workspaceName: string,
workspaceAgent: string,
workspaceAgent: string | undefined,
folderPath: string | undefined,
openRecent: boolean | undefined,
) {
let remoteAuthority = toRemoteAuthority(baseUrl, workspaceOwner, workspaceName, workspaceAgent)

let hostnameSuffix = "coder"
try {
const sshConfig = await restClient.getDeploymentSSHConfig()
// If the field is undefined, it's an older server, and always 'coder'
hostnameSuffix = sshConfig.hostname_suffix ?? hostnameSuffix
} catch (error) {
if (!isAxiosError(error)) {
throw error
}
switch (error.response?.status) {
case 404: {
// Likely a very old deployment, just use the default.
break
}
case 401: {
// When called from `openFromSidebar`, the workspaceAgent will only not be set
// if the workspace is stopped, in which case we can't use Coder Connect
// When called from `open`, the workspaceAgent will always be set.
if (workspaceAgent) {
let hostnameSuffix = "coder"
try {
const sshConfig = await restClient.getDeploymentSSHConfig()
// If the field is undefined, it's an older server, and always 'coder'
hostnameSuffix = sshConfig.hostname_suffix ?? hostnameSuffix
} catch (error) {
if (!isAxiosError(error)) {
throw error
}
default:
throw error
switch (error.response?.status) {
case 404: {
// Likely a very old deployment, just use the default.
break
}
case 401: {
throw error
}
default:
throw error
}
}
const coderConnectAddr = await maybeCoderConnectAddr(workspaceAgent, workspaceName, workspaceOwner, hostnameSuffix)
if (coderConnectAddr) {
remoteAuthority = `ssh-remote+${coderConnectAddr}`
}
}

const coderConnectAddr = await maybeCoderConnectAddr(workspaceAgent, workspaceName, workspaceOwner, hostnameSuffix)
if (coderConnectAddr) {
remoteAuthority = `ssh-remote+${coderConnectAddr}`
}

let newWindow = true
Expand Down