Skip to content

fix: FE show correct config-ssh prefix #6904

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 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions site/src/components/Resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface AgentRowProps {
applicationsHost: string | undefined
showApps: boolean
hideSSHButton?: boolean
sshPrefix?: string
hideVSCodeDesktopButton?: boolean
serverVersion: string
onUpdateAgent: () => void
Expand All @@ -61,6 +62,7 @@ export const AgentRow: FC<AgentRowProps> = ({
serverVersion,
onUpdateAgent,
storybookStartupLogs,
sshPrefix,
}) => {
const styles = useStyles()
const { t } = useTranslation("agent")
Expand Down Expand Up @@ -308,6 +310,7 @@ export const AgentRow: FC<AgentRowProps> = ({
<SSHButton
workspaceName={workspace.name}
agentName={agent.name}
sshPrefix={sshPrefix}
/>
)}
{!hideVSCodeDesktopButton && (
Expand Down
2 changes: 2 additions & 0 deletions site/src/components/SSHButton/SSHButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export const Closed = Template.bind({})
Closed.args = {
workspaceName: MockWorkspace.name,
agentName: MockWorkspaceAgent.name,
sshPrefix: "coder.",
}

export const Opened = Template.bind({})
Opened.args = {
workspaceName: MockWorkspace.name,
agentName: MockWorkspaceAgent.name,
defaultIsOpen: true,
sshPrefix: "coder.",
}
6 changes: 5 additions & 1 deletion site/src/components/SSHButton/SSHButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export interface SSHButtonProps {
workspaceName: string
agentName: string
defaultIsOpen?: boolean
sshPrefix?: string
}

export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
workspaceName,
agentName,
defaultIsOpen = false,
sshPrefix,
}) => {
const anchorRef = useRef<HTMLButtonElement>(null)
const [isOpen, setIsOpen] = useState(defaultIsOpen)
Expand Down Expand Up @@ -79,7 +81,9 @@ export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
Connect to the agent:
</strong>
</HelpTooltipText>
<CodeExample code={`ssh coder.${workspaceName}.${agentName}`} />
<CodeExample
code={`ssh ${sshPrefix}${workspaceName}.${agentName}`}
/>
</div>
</Stack>

Expand Down
3 changes: 3 additions & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface WorkspaceProps {
workspaceErrors: Partial<Record<WorkspaceErrors, Error | unknown>>
buildInfo?: TypesGen.BuildInfoResponse
applicationsHost?: string
sshPrefix?: string
template?: TypesGen.Template
quota_budget?: number
}
Expand All @@ -78,6 +79,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
hideVSCodeDesktopButton,
buildInfo,
applicationsHost,
sshPrefix,
template,
quota_budget,
}) => {
Expand Down Expand Up @@ -193,6 +195,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
agent={agent}
workspace={workspace}
applicationsHost={applicationsHost}
sshPrefix={sshPrefix}
showApps={canUpdateWorkspace}
hideSSHButton={hideSSHButton}
hideVSCodeDesktopButton={hideVSCodeDesktopButton}
Expand Down
2 changes: 2 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const WorkspaceReadyPage = ({
buildError,
cancellationError,
applicationsHost,
sshPrefix,
permissions,
missedParameters,
} = workspaceState.context
Expand Down Expand Up @@ -124,6 +125,7 @@ export const WorkspaceReadyPage = ({
}}
buildInfo={buildInfo}
applicationsHost={applicationsHost}
sshPrefix={sshPrefix}
template={template}
quota_budget={quotaState.context.quota?.budget}
/>
Expand Down
43 changes: 43 additions & 0 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface WorkspaceContext {
checkPermissionsError?: Error | unknown
// applications
applicationsHost?: string
// SSH Config
sshPrefix?: string
}

export type WorkspaceEvent =
Expand Down Expand Up @@ -162,6 +164,9 @@ export const workspaceMachine = createMachine(
getApplicationsHost: {
data: TypesGen.AppHostResponse
}
getSSHPrefix: {
data: TypesGen.SSHConfigResponse
}
},
},
initial: "idle",
Expand Down Expand Up @@ -456,6 +461,30 @@ export const workspaceMachine = createMachine(
},
},
},
sshConfig: {
initial: "gettingSshConfig",
states: {
gettingSshConfig: {
invoke: {
src: "getSSHPrefix",
onDone: {
target: "success",
actions: ["assignSSHPrefix"],
},
onError: {
target: "error",
actions: ["displaySSHPrefixError"],
},
},
},
error: {
type: "final",
},
success: {
type: "final",
},
},
},
schedule: {
invoke: {
id: "scheduleBannerMachine",
Expand Down Expand Up @@ -579,6 +608,17 @@ export const workspaceMachine = createMachine(
)
displayError(message)
},
// SSH
assignSSHPrefix: assign({
sshPrefix: (_, { data }) => data.hostname_prefix,
}),
displaySSHPrefixError: (_, { data }) => {
const message = getErrorMessage(
data,
"Error getting the deployment ssh configuration.",
)
displayError(message)
},
// Optimistically update. So when the user clicks on stop, we can show
// the "pending" state right away without having to wait 0.5s ~ 2s to
// display the visual feedback to the user.
Expand Down Expand Up @@ -736,6 +776,9 @@ export const workspaceMachine = createMachine(
getApplicationsHost: async () => {
return API.getApplicationsHost()
},
getSSHPrefix: async () => {
return API.getDeploymentSSHConfig()
},
},
},
)