Skip to content

Commit 2388cae

Browse files
committed
Extract ssh config
1 parent b6ee59a commit 2388cae

File tree

3 files changed

+13
-52
lines changed

3 files changed

+13
-52
lines changed

site/src/api/queries/deployment.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ export const health = () => {
2727
queryFn: API.getHealth,
2828
};
2929
};
30+
31+
export const deploymentSSHConfig = () => {
32+
return {
33+
queryKey: ["deployment", "sshConfig"],
34+
queryFn: API.getDeploymentSSHConfig,
35+
};
36+
};

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { useWorkspaceBuildLogs } from "hooks/useWorkspaceBuildLogs";
3636
import { decreaseDeadline, increaseDeadline } from "api/queries/workspaces";
3737
import { getErrorMessage } from "api/errors";
3838
import { displaySuccess, displayError } from "components/GlobalSnackbar/utils";
39-
import { deploymentConfig } from "api/queries/deployment";
39+
import { deploymentConfig, deploymentSSHConfig } from "api/queries/deployment";
4040
import { WorkspacePermissions } from "./permissions";
4141
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
4242

@@ -70,7 +70,7 @@ export const WorkspaceReadyPage = ({
7070
}: WorkspaceReadyPageProps): JSX.Element => {
7171
const { buildInfo } = useDashboard();
7272
const featureVisibility = useFeatureVisibility();
73-
const { buildError, cancellationError, sshPrefix, missedParameters } =
73+
const { buildError, cancellationError, missedParameters } =
7474
workspaceState.context;
7575
if (workspace === undefined) {
7676
throw Error("Workspace is undefined");
@@ -150,6 +150,8 @@ export const WorkspaceReadyPage = ({
150150
);
151151
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;
152152

153+
const sshPrefixQuery = useQuery(deploymentSSHConfig());
154+
153155
return (
154156
<>
155157
<Helmet>
@@ -214,7 +216,7 @@ export const WorkspaceReadyPage = ({
214216
[WorkspaceErrors.CANCELLATION_ERROR]: cancellationError,
215217
}}
216218
buildInfo={buildInfo}
217-
sshPrefix={sshPrefix}
219+
sshPrefix={sshPrefixQuery.data?.hostname_prefix}
218220
template={template}
219221
buildLogs={
220222
shouldDisplayBuildLogs && (

site/src/xServices/workspace/workspaceXService.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ export interface WorkspaceContext {
2626
cancellationError?: unknown;
2727
// debug
2828
createBuildLogLevel?: TypesGen.CreateWorkspaceBuildRequest["log_level"];
29-
// SSH Config
30-
sshPrefix?: string;
3129
// Change version
3230
templateVersionIdToChange?: TypesGen.TemplateVersion["id"];
3331
}
3432

3533
export type WorkspaceEvent =
36-
| { type: "LOAD" }
3734
| { type: "REFRESH_WORKSPACE"; data: TypesGen.ServerSentEvent["data"] }
3835
| { type: "START"; buildParameters?: TypesGen.WorkspaceBuildParameter[] }
3936
| { type: "STOP" }
@@ -97,15 +94,8 @@ export const workspaceMachine = createMachine(
9794
};
9895
},
9996
},
100-
initial: "loadInitialData",
97+
initial: "ready",
10198
states: {
102-
loadInitialData: {
103-
on: {
104-
LOAD: {
105-
target: "ready",
106-
},
107-
},
108-
},
10999
ready: {
110100
type: "parallel",
111101
on: {
@@ -334,30 +324,6 @@ export const workspaceMachine = createMachine(
334324
},
335325
},
336326
},
337-
sshConfig: {
338-
initial: "gettingSshConfig",
339-
states: {
340-
gettingSshConfig: {
341-
invoke: {
342-
src: "getSSHPrefix",
343-
onDone: {
344-
target: "success",
345-
actions: ["assignSSHPrefix"],
346-
},
347-
onError: {
348-
target: "error",
349-
actions: ["displaySSHPrefixError"],
350-
},
351-
},
352-
},
353-
error: {
354-
type: "final",
355-
},
356-
success: {
357-
type: "final",
358-
},
359-
},
360-
},
361327
},
362328
},
363329
error: {
@@ -407,17 +373,6 @@ export const workspaceMachine = createMachine(
407373
logWatchWorkspaceWarning: (_, event) => {
408374
console.error("Watch workspace error:", event);
409375
},
410-
// SSH
411-
assignSSHPrefix: assign({
412-
sshPrefix: (_, { data }) => data.hostname_prefix,
413-
}),
414-
displaySSHPrefixError: (_, { data }) => {
415-
const message = getErrorMessage(
416-
data,
417-
"Error getting the deployment ssh configuration.",
418-
);
419-
displayError(message);
420-
},
421376
displayActivateError: (_, { data }) => {
422377
const message = getErrorMessage(data, "Error activate workspace.");
423378
displayError(message);
@@ -585,9 +540,6 @@ export const workspaceMachine = createMachine(
585540
context.eventSource?.close();
586541
};
587542
},
588-
getSSHPrefix: async () => {
589-
return API.getDeploymentSSHConfig();
590-
},
591543
},
592544
},
593545
);

0 commit comments

Comments
 (0)