Skip to content

Commit a748927

Browse files
committed
fix: Push correct ssh prefix to FE
1 parent 665b84d commit a748927

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

site/src/components/Resources/AgentRow.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface AgentRowProps {
4444
applicationsHost: string | undefined
4545
showApps: boolean
4646
hideSSHButton?: boolean
47+
sshPrefix?: string
4748
hideVSCodeDesktopButton?: boolean
4849
serverVersion: string
4950
onUpdateAgent: () => void
@@ -61,6 +62,7 @@ export const AgentRow: FC<AgentRowProps> = ({
6162
serverVersion,
6263
onUpdateAgent,
6364
storybookStartupLogs,
65+
sshPrefix,
6466
}) => {
6567
const styles = useStyles()
6668
const { t } = useTranslation("agent")
@@ -308,6 +310,7 @@ export const AgentRow: FC<AgentRowProps> = ({
308310
<SSHButton
309311
workspaceName={workspace.name}
310312
agentName={agent.name}
313+
sshPrefix={sshPrefix}
311314
/>
312315
)}
313316
{!hideVSCodeDesktopButton && (

site/src/components/SSHButton/SSHButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export interface SSHButtonProps {
1515
workspaceName: string
1616
agentName: string
1717
defaultIsOpen?: boolean
18+
sshPrefix?: string
1819
}
1920

2021
export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
2122
workspaceName,
2223
agentName,
2324
defaultIsOpen = false,
25+
sshPrefix,
2426
}) => {
2527
const anchorRef = useRef<HTMLButtonElement>(null)
2628
const [isOpen, setIsOpen] = useState(defaultIsOpen)
@@ -79,7 +81,7 @@ export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
7981
Connect to the agent:
8082
</strong>
8183
</HelpTooltipText>
82-
<CodeExample code={`ssh coder.${workspaceName}.${agentName}`} />
84+
<CodeExample code={`ssh ${sshPrefix}${workspaceName}.${agentName}`} />
8385
</div>
8486
</Stack>
8587

site/src/components/Workspace/Workspace.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface WorkspaceProps {
5353
workspaceErrors: Partial<Record<WorkspaceErrors, Error | unknown>>
5454
buildInfo?: TypesGen.BuildInfoResponse
5555
applicationsHost?: string
56+
sshPrefix?: string
5657
template?: TypesGen.Template
5758
quota_budget?: number
5859
}
@@ -78,6 +79,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
7879
hideVSCodeDesktopButton,
7980
buildInfo,
8081
applicationsHost,
82+
sshPrefix,
8183
template,
8284
quota_budget,
8385
}) => {
@@ -193,6 +195,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
193195
agent={agent}
194196
workspace={workspace}
195197
applicationsHost={applicationsHost}
198+
sshPrefix={sshPrefix}
196199
showApps={canUpdateWorkspace}
197200
hideSSHButton={hideSSHButton}
198201
hideVSCodeDesktopButton={hideVSCodeDesktopButton}

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const WorkspaceReadyPage = ({
5151
buildError,
5252
cancellationError,
5353
applicationsHost,
54+
sshPrefix,
5455
permissions,
5556
missedParameters,
5657
} = workspaceState.context
@@ -124,6 +125,7 @@ export const WorkspaceReadyPage = ({
124125
}}
125126
buildInfo={buildInfo}
126127
applicationsHost={applicationsHost}
128+
sshPrefix={sshPrefix}
127129
template={template}
128130
quota_budget={quotaState.context.quota?.budget}
129131
/>

site/src/xServices/workspace/workspaceXService.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export interface WorkspaceContext {
7272
checkPermissionsError?: Error | unknown
7373
// applications
7474
applicationsHost?: string
75+
// SSH Config
76+
sshPrefix?: string
7577
}
7678

7779
export type WorkspaceEvent =
@@ -162,6 +164,9 @@ export const workspaceMachine = createMachine(
162164
getApplicationsHost: {
163165
data: TypesGen.AppHostResponse
164166
}
167+
getSSHPrefix: {
168+
data: TypesGen.SSHConfigResponse
169+
}
165170
},
166171
},
167172
initial: "idle",
@@ -456,6 +461,30 @@ export const workspaceMachine = createMachine(
456461
},
457462
},
458463
},
464+
sshConfig: {
465+
initial: "gettingSshConfig",
466+
states: {
467+
gettingSshConfig: {
468+
invoke: {
469+
src: "getSSHPrefix",
470+
onDone: {
471+
target: "success",
472+
actions: ["assignSSHPrefix"],
473+
},
474+
onError: {
475+
target: "error",
476+
actions: ["displaySSHPrefixError"],
477+
},
478+
},
479+
},
480+
error: {
481+
type: "final",
482+
},
483+
success: {
484+
type: "final",
485+
},
486+
},
487+
},
459488
schedule: {
460489
invoke: {
461490
id: "scheduleBannerMachine",
@@ -579,6 +608,17 @@ export const workspaceMachine = createMachine(
579608
)
580609
displayError(message)
581610
},
611+
// SSH
612+
assignSSHPrefix: assign({
613+
sshPrefix: (_, { data }) => data.hostname_prefix,
614+
}),
615+
displaySSHPrefixError: (_, { data }) => {
616+
const message = getErrorMessage(
617+
data,
618+
"Error getting the deployment ssh configuration.",
619+
)
620+
displayError(message)
621+
},
582622
// Optimistically update. So when the user clicks on stop, we can show
583623
// the "pending" state right away without having to wait 0.5s ~ 2s to
584624
// display the visual feedback to the user.
@@ -736,6 +776,9 @@ export const workspaceMachine = createMachine(
736776
getApplicationsHost: async () => {
737777
return API.getApplicationsHost()
738778
},
779+
getSSHPrefix: async () => {
780+
return API.getDeploymentSSHConfig()
781+
},
739782
},
740783
},
741784
)

0 commit comments

Comments
 (0)