mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: FE show correct config-ssh prefix (#6904)
* fix: Push correct ssh prefix to FE
This commit is contained in:
@@ -44,6 +44,7 @@ export interface AgentRowProps {
|
|||||||
applicationsHost: string | undefined
|
applicationsHost: string | undefined
|
||||||
showApps: boolean
|
showApps: boolean
|
||||||
hideSSHButton?: boolean
|
hideSSHButton?: boolean
|
||||||
|
sshPrefix?: string
|
||||||
hideVSCodeDesktopButton?: boolean
|
hideVSCodeDesktopButton?: boolean
|
||||||
serverVersion: string
|
serverVersion: string
|
||||||
onUpdateAgent: () => void
|
onUpdateAgent: () => void
|
||||||
@@ -61,6 +62,7 @@ export const AgentRow: FC<AgentRowProps> = ({
|
|||||||
serverVersion,
|
serverVersion,
|
||||||
onUpdateAgent,
|
onUpdateAgent,
|
||||||
storybookStartupLogs,
|
storybookStartupLogs,
|
||||||
|
sshPrefix,
|
||||||
}) => {
|
}) => {
|
||||||
const styles = useStyles()
|
const styles = useStyles()
|
||||||
const { t } = useTranslation("agent")
|
const { t } = useTranslation("agent")
|
||||||
@@ -308,6 +310,7 @@ export const AgentRow: FC<AgentRowProps> = ({
|
|||||||
<SSHButton
|
<SSHButton
|
||||||
workspaceName={workspace.name}
|
workspaceName={workspace.name}
|
||||||
agentName={agent.name}
|
agentName={agent.name}
|
||||||
|
sshPrefix={sshPrefix}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!hideVSCodeDesktopButton && (
|
{!hideVSCodeDesktopButton && (
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const Closed = Template.bind({})
|
|||||||
Closed.args = {
|
Closed.args = {
|
||||||
workspaceName: MockWorkspace.name,
|
workspaceName: MockWorkspace.name,
|
||||||
agentName: MockWorkspaceAgent.name,
|
agentName: MockWorkspaceAgent.name,
|
||||||
|
sshPrefix: "coder.",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Opened = Template.bind({})
|
export const Opened = Template.bind({})
|
||||||
@@ -20,4 +21,5 @@ Opened.args = {
|
|||||||
workspaceName: MockWorkspace.name,
|
workspaceName: MockWorkspace.name,
|
||||||
agentName: MockWorkspaceAgent.name,
|
agentName: MockWorkspaceAgent.name,
|
||||||
defaultIsOpen: true,
|
defaultIsOpen: true,
|
||||||
|
sshPrefix: "coder.",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ export interface SSHButtonProps {
|
|||||||
workspaceName: string
|
workspaceName: string
|
||||||
agentName: string
|
agentName: string
|
||||||
defaultIsOpen?: boolean
|
defaultIsOpen?: boolean
|
||||||
|
sshPrefix?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
|
export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
|
||||||
workspaceName,
|
workspaceName,
|
||||||
agentName,
|
agentName,
|
||||||
defaultIsOpen = false,
|
defaultIsOpen = false,
|
||||||
|
sshPrefix,
|
||||||
}) => {
|
}) => {
|
||||||
const anchorRef = useRef<HTMLButtonElement>(null)
|
const anchorRef = useRef<HTMLButtonElement>(null)
|
||||||
const [isOpen, setIsOpen] = useState(defaultIsOpen)
|
const [isOpen, setIsOpen] = useState(defaultIsOpen)
|
||||||
@@ -79,7 +81,9 @@ export const SSHButton: React.FC<React.PropsWithChildren<SSHButtonProps>> = ({
|
|||||||
Connect to the agent:
|
Connect to the agent:
|
||||||
</strong>
|
</strong>
|
||||||
</HelpTooltipText>
|
</HelpTooltipText>
|
||||||
<CodeExample code={`ssh coder.${workspaceName}.${agentName}`} />
|
<CodeExample
|
||||||
|
code={`ssh ${sshPrefix}${workspaceName}.${agentName}`}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export interface WorkspaceProps {
|
|||||||
workspaceErrors: Partial<Record<WorkspaceErrors, Error | unknown>>
|
workspaceErrors: Partial<Record<WorkspaceErrors, Error | unknown>>
|
||||||
buildInfo?: TypesGen.BuildInfoResponse
|
buildInfo?: TypesGen.BuildInfoResponse
|
||||||
applicationsHost?: string
|
applicationsHost?: string
|
||||||
|
sshPrefix?: string
|
||||||
template?: TypesGen.Template
|
template?: TypesGen.Template
|
||||||
quota_budget?: number
|
quota_budget?: number
|
||||||
}
|
}
|
||||||
@@ -78,6 +79,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
|
|||||||
hideVSCodeDesktopButton,
|
hideVSCodeDesktopButton,
|
||||||
buildInfo,
|
buildInfo,
|
||||||
applicationsHost,
|
applicationsHost,
|
||||||
|
sshPrefix,
|
||||||
template,
|
template,
|
||||||
quota_budget,
|
quota_budget,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -193,6 +195,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
|
|||||||
agent={agent}
|
agent={agent}
|
||||||
workspace={workspace}
|
workspace={workspace}
|
||||||
applicationsHost={applicationsHost}
|
applicationsHost={applicationsHost}
|
||||||
|
sshPrefix={sshPrefix}
|
||||||
showApps={canUpdateWorkspace}
|
showApps={canUpdateWorkspace}
|
||||||
hideSSHButton={hideSSHButton}
|
hideSSHButton={hideSSHButton}
|
||||||
hideVSCodeDesktopButton={hideVSCodeDesktopButton}
|
hideVSCodeDesktopButton={hideVSCodeDesktopButton}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export const WorkspaceReadyPage = ({
|
|||||||
buildError,
|
buildError,
|
||||||
cancellationError,
|
cancellationError,
|
||||||
applicationsHost,
|
applicationsHost,
|
||||||
|
sshPrefix,
|
||||||
permissions,
|
permissions,
|
||||||
missedParameters,
|
missedParameters,
|
||||||
} = workspaceState.context
|
} = workspaceState.context
|
||||||
@@ -124,6 +125,7 @@ export const WorkspaceReadyPage = ({
|
|||||||
}}
|
}}
|
||||||
buildInfo={buildInfo}
|
buildInfo={buildInfo}
|
||||||
applicationsHost={applicationsHost}
|
applicationsHost={applicationsHost}
|
||||||
|
sshPrefix={sshPrefix}
|
||||||
template={template}
|
template={template}
|
||||||
quota_budget={quotaState.context.quota?.budget}
|
quota_budget={quotaState.context.quota?.budget}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ export interface WorkspaceContext {
|
|||||||
checkPermissionsError?: Error | unknown
|
checkPermissionsError?: Error | unknown
|
||||||
// applications
|
// applications
|
||||||
applicationsHost?: string
|
applicationsHost?: string
|
||||||
|
// SSH Config
|
||||||
|
sshPrefix?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspaceEvent =
|
export type WorkspaceEvent =
|
||||||
@@ -163,6 +165,9 @@ export const workspaceMachine = createMachine(
|
|||||||
getApplicationsHost: {
|
getApplicationsHost: {
|
||||||
data: TypesGen.AppHostResponse
|
data: TypesGen.AppHostResponse
|
||||||
}
|
}
|
||||||
|
getSSHPrefix: {
|
||||||
|
data: TypesGen.SSHConfigResponse
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
initial: "idle",
|
initial: "idle",
|
||||||
@@ -457,6 +462,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: {
|
schedule: {
|
||||||
invoke: {
|
invoke: {
|
||||||
id: "scheduleBannerMachine",
|
id: "scheduleBannerMachine",
|
||||||
@@ -580,6 +609,17 @@ export const workspaceMachine = createMachine(
|
|||||||
)
|
)
|
||||||
displayError(message)
|
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
|
// 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
|
// the "pending" state right away without having to wait 0.5s ~ 2s to
|
||||||
// display the visual feedback to the user.
|
// display the visual feedback to the user.
|
||||||
@@ -737,6 +777,9 @@ export const workspaceMachine = createMachine(
|
|||||||
getApplicationsHost: async () => {
|
getApplicationsHost: async () => {
|
||||||
return API.getApplicationsHost()
|
return API.getApplicationsHost()
|
||||||
},
|
},
|
||||||
|
getSSHPrefix: async () => {
|
||||||
|
return API.getDeploymentSSHConfig()
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user