Skip to content

Commit 901045a

Browse files
authored
fix: FE show correct config-ssh prefix (coder#6904)
* fix: Push correct ssh prefix to FE
1 parent a364318 commit 901045a

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-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.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export const Closed = Template.bind({})
1313
Closed.args = {
1414
workspaceName: MockWorkspace.name,
1515
agentName: MockWorkspaceAgent.name,
16+
sshPrefix: "coder.",
1617
}
1718

1819
export const Opened = Template.bind({})
1920
Opened.args = {
2021
workspaceName: MockWorkspace.name,
2122
agentName: MockWorkspaceAgent.name,
2223
defaultIsOpen: true,
24+
sshPrefix: "coder.",
2325
}

site/src/components/SSHButton/SSHButton.tsx

Lines changed: 5 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,9 @@ 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
85+
code={`ssh ${sshPrefix}${workspaceName}.${agentName}`}
86+
/>
8387
</div>
8488
</Stack>
8589

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
@@ -73,6 +73,8 @@ export interface WorkspaceContext {
7373
checkPermissionsError?: Error | unknown
7474
// applications
7575
applicationsHost?: string
76+
// SSH Config
77+
sshPrefix?: string
7678
}
7779

7880
export type WorkspaceEvent =
@@ -163,6 +165,9 @@ export const workspaceMachine = createMachine(
163165
getApplicationsHost: {
164166
data: TypesGen.AppHostResponse
165167
}
168+
getSSHPrefix: {
169+
data: TypesGen.SSHConfigResponse
170+
}
166171
},
167172
},
168173
initial: "idle",
@@ -457,6 +462,30 @@ export const workspaceMachine = createMachine(
457462
},
458463
},
459464
},
465+
sshConfig: {
466+
initial: "gettingSshConfig",
467+
states: {
468+
gettingSshConfig: {
469+
invoke: {
470+
src: "getSSHPrefix",
471+
onDone: {
472+
target: "success",
473+
actions: ["assignSSHPrefix"],
474+
},
475+
onError: {
476+
target: "error",
477+
actions: ["displaySSHPrefixError"],
478+
},
479+
},
480+
},
481+
error: {
482+
type: "final",
483+
},
484+
success: {
485+
type: "final",
486+
},
487+
},
488+
},
460489
schedule: {
461490
invoke: {
462491
id: "scheduleBannerMachine",
@@ -580,6 +609,17 @@ export const workspaceMachine = createMachine(
580609
)
581610
displayError(message)
582611
},
612+
// SSH
613+
assignSSHPrefix: assign({
614+
sshPrefix: (_, { data }) => data.hostname_prefix,
615+
}),
616+
displaySSHPrefixError: (_, { data }) => {
617+
const message = getErrorMessage(
618+
data,
619+
"Error getting the deployment ssh configuration.",
620+
)
621+
displayError(message)
622+
},
583623
// Optimistically update. So when the user clicks on stop, we can show
584624
// the "pending" state right away without having to wait 0.5s ~ 2s to
585625
// display the visual feedback to the user.
@@ -737,6 +777,9 @@ export const workspaceMachine = createMachine(
737777
getApplicationsHost: async () => {
738778
return API.getApplicationsHost()
739779
},
780+
getSSHPrefix: async () => {
781+
return API.getDeploymentSSHConfig()
782+
},
740783
},
741784
},
742785
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy