-
Notifications
You must be signed in to change notification settings - Fork 43
Add alternativeWebUrl param
#956
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import * as os from "node:os"; | ||
| import url from "node:url"; | ||
| import * as vscode from "vscode"; | ||
|
|
||
| export interface AuthorityParts { | ||
| agent: string | undefined; | ||
|
|
@@ -202,6 +203,20 @@ export async function renameWithRetry( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return the URL for opening Coder pages in the browser. Uses the | ||
| * `coder.alternativeWebUrl` setting when configured, otherwise returns | ||
| * the connection URL unchanged. | ||
| */ | ||
| export function resolveBrowserUrl(connectionUrl: string): string { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const alt = vscode.workspace | ||
| .getConfiguration("coder") | ||
| .get<string>("alternativeWebUrl") | ||
| ?.trim() | ||
| .replace(/\/+$/, ""); | ||
| return alt || connectionUrl; | ||
| } | ||
|
|
||
| export function escapeCommandArg(arg: string): string { | ||
| const escapedString = arg.replaceAll('"', String.raw`\"`); | ||
| return `"${escapedString}"`; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |
|
|
||
| import { type CoderApi } from "../../api/coderApi"; | ||
| import { type Logger } from "../../logging/logger"; | ||
| import { resolveBrowserUrl } from "../../util"; | ||
| import { | ||
| dispatchCommand, | ||
| dispatchRequest, | ||
|
|
@@ -154,7 +155,12 @@ export class ChatPanelProvider | |
| const resolved = new URL(url, coderUrl); | ||
| const expected = new URL(coderUrl); | ||
| if (resolved.origin === expected.origin) { | ||
| void vscode.env.openExternal(vscode.Uri.parse(resolved.toString())); | ||
| const browserBase = resolveBrowserUrl(coderUrl); | ||
| const browserUrl = new URL( | ||
| resolved.pathname + resolved.search + resolved.hash, | ||
| browserBase, | ||
| ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed! |
||
| void vscode.env.openExternal(vscode.Uri.parse(browserUrl.toString())); | ||
| } | ||
| } catch { | ||
| this.logger.warn(`Chat: invalid navigate URL: ${url}`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import { | |
| streamBuildLogs, | ||
| } from "../../api/workspace"; | ||
| import { type Logger } from "../../logging/logger"; | ||
| import { resolveBrowserUrl } from "../../util"; | ||
| import { vscodeProposed } from "../../vscodeProposed"; | ||
| import { | ||
| dispatchCommand, | ||
|
|
@@ -308,19 +309,21 @@ export class TasksPanelProvider | |
| } | ||
|
|
||
| private async handleViewInCoder(taskId: string): Promise<void> { | ||
| const baseUrl = this.client.getHost(); | ||
| if (!baseUrl) return; | ||
| const connUrl = this.client.getHost(); | ||
| if (!connUrl) return; | ||
|
|
||
| const baseUrl = resolveBrowserUrl(connUrl); | ||
| const task = await this.client.getTask("me", taskId); | ||
| vscode.env.openExternal( | ||
| vscode.Uri.parse(`${baseUrl}/tasks/${task.owner_name}/${task.id}`), | ||
| ); | ||
| } | ||
|
|
||
| private async handleViewLogs(taskId: string): Promise<void> { | ||
| const baseUrl = this.client.getHost(); | ||
| if (!baseUrl) return; | ||
| const connUrl = this.client.getHost(); | ||
| if (!connUrl) return; | ||
|
|
||
| const baseUrl = resolveBrowserUrl(connUrl); | ||
| const task = await this.client.getTask("me", taskId); | ||
| vscode.env.openExternal(vscode.Uri.parse(getTaskBuildUrl(baseUrl, task))); | ||
|
Comment on lines
+326
to
328
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of always doing
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could even do it in a safer way like |
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,13 @@ describe("ChatPanelProvider", () => { | |
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| windowMock.__setActiveColorThemeKind(vscode.ColorThemeKind.Dark); | ||
|
|
||
| vi.mocked(vscode.workspace.getConfiguration).mockReturnValue({ | ||
| get: vi.fn(), | ||
|
Comment on lines
+91
to
+92
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do use |
||
| has: vi.fn().mockReturnValue(false), | ||
| inspect: vi.fn(), | ||
| update: vi.fn().mockResolvedValue(undefined), | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
| }); | ||
|
|
||
| describe("theme sync", () => { | ||
|
|
@@ -171,6 +178,23 @@ describe("ChatPanelProvider", () => { | |
| ); | ||
| }); | ||
|
|
||
| it("uses alternative web URL for navigation when configured", () => { | ||
| vi.mocked(vscode.workspace.getConfiguration).mockReturnValue({ | ||
| get: vi.fn().mockReturnValue("https://web.example.com"), | ||
| } as unknown as vscode.WorkspaceConfiguration); | ||
|
|
||
| const { sendFromWebview } = createHarness(); | ||
|
|
||
| sendFromWebview({ | ||
| method: "coder:navigate", | ||
| params: { url: "/templates" }, | ||
| }); | ||
|
|
||
| expect(vscode.env.openExternal).toHaveBeenCalledWith( | ||
| vscode.Uri.parse("https://web.example.com/templates"), | ||
| ); | ||
| }); | ||
|
|
||
| it("ignores navigate without url payload", () => { | ||
| const { sendFromWebview } = createHarness(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only switches the legacy token page to
coder.alternativeWebUrl; whencoder.experimental.oauthis enabled and the user chooses OAuth,loginWithOAuthstill goes throughOAuthAuthorizer.startAuthorization, which opens the discovered authorization URL directly. In deployments where the connection URL uses a browser-restricted/unreachable port and the web UI is available via the alternative URL, OAuth login still opens the restricted connection URL and cannot complete, while token login works.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't touch the OAuth path deliberately, but I think the case highlighted here is worth addressing so we have consistency. Will submit a fix shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed!