8000 chore(site): remove terminal xservice by code-asher · Pull Request #10234 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore(site): remove terminal xservice #10234

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 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Break out getting terminal websocket url
To make it easier to move away from this service.
  • Loading branch information
code-asher committed Oct 19, 2023
commit 1b99882960a37633fe8582f8e11a482c44dd39fa
37 changes: 37 additions & 0 deletions site/src/utils/terminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as API from "api/api";

export const terminalWebsocketUrl = async (
baseUrl: string | undefined,
reconnect: string,
agentId: string,
command: string | undefined,
): Promise<string> => {
const query = new URLSearchParams({ reconnect });
if (command) {
query.set("command", command);
}

const url = new URL(baseUrl || `${location.protocol}//${location.host}`);
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
if (!url.pathname.endsWith("/")) {
url.pathname + "/";
}
url.pathname += `api/v2/workspaceagents/${agentId}/ 10000 pty`;
url.search = "?" + query.toString();

// If the URL is just the primary API, we don't need a signed token to
// connect.
if (!baseUrl) {
return url.toString();
}

// Do ticket issuance and set the query parameter.
const tokenRes = await API.issueReconnectingPTYSignedToken({
url: url.toString(),
agentID: agentId,
});
query.set("coder_signed_app_token_23db1dde", tokenRes.signed_token);
url.search = "?" + query.toString();

return url.toString();
};
43 changes: 7 additions & 36 deletions site/src/xServices/terminal/terminalXService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assign, createMachine } from "xstate";
import * as API from "api/api";
import * as TypesGen from "api/typesGenerated";
import { terminalWebsocketUrl } from "utils/terminal";
import { getMatchingAgentOrFirst } from "utils/workspace";

interface ReconnectingPTYRequest {
Expand Down Expand Up @@ -213,42 +214,12 @@ export const terminalMachine =
if (!context.reconnection) {
throw new Error("reconnection ID is not set");
}

let baseURL = context.baseURL || "";
if (!baseURL) {
baseURL = `${location.protocol}//${location.host}`;
}

const query = new URLSearchParams({
reconnect: context.reconnection,
});
if (context.command) {
query.set("command", context.command);
}

const url = new URL(baseURL);
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
if (!url.pathname.endsWith("/")) {
url.pathname + "/";
}
url.pathname += `api/v2/workspaceagents/${context.workspaceAgent.id}/pty`;
url.search = "?" + query.toString();

// If the URL is just the primary API, we don't need a signed token to
// connect.
if (!context.baseURL) {
return url.toString();
}

// Do ticket issuance and set the query parameter.
const tokenRes = await API.issueReconnectingPTYSignedToken({
url: url.toString(),
agentID: context.workspaceAgent.id,
});
query.set("coder_signed_app_token_23db1dde", tokenRes.signed_token);
url.search = "?" + query.toString();

return url.toString();
return terminalWebsocketUrl(
context.baseURL,
context.reconnection,
context.workspaceAgent.id,
context.command,
);
},
connect: (context) => (send) => {
return new Promise<WebSocket>((resolve, reject) => {
Expand Down
0