Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/workspaces/ConnectToSSHModal.tsx
2500 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useEffect, useState } from "react";
8
import Modal, { ModalBody, ModalFooter, ModalHeader } from "../components/Modal";
9
import Alert from "../components/Alert";
10
import { settingsPathSSHKeys } from "../user-settings/settings.routes";
11
import { InputWithCopy } from "../components/InputWithCopy";
12
import { Link } from "react-router-dom";
13
import { Button } from "@podkit/buttons/Button";
14
import { sshClient } from "../service/public-api";
15
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@podkit/tabs/Tabs";
16
17
interface SSHProps {
18
workspaceId: string;
19
ownerToken: string;
20
ideUrl: string;
21
}
22
23
function SSHView(props: SSHProps) {
24
const [hasSSHKey, setHasSSHKey] = useState(true);
25
26
useEffect(() => {
27
sshClient
28
.listSSHPublicKeys({})
29
.then((r) => {
30
setHasSSHKey(r.sshKeys.length > 0);
31
})
32
.catch(console.error);
33
}, []);
34
35
const host = props.ideUrl.replace(props.workspaceId, props.workspaceId + ".ssh");
36
const sshAccessTokenCommand = `ssh '${props.workspaceId}#${props.ownerToken}@${host}'`;
37
const sshKeyCommand = `ssh '${props.workspaceId}@${host}'`;
38
39
return (
40
<>
41
<Tabs defaultValue="ssh_key">
42
<TabsList className="flex flex-row items-start">
43
<TabsTrigger value="ssh_key" className="text-base">
44
{" "}
45
SSH Key{" "}
46
</TabsTrigger>
47
<TabsTrigger value="access_token" className="text-base">
48
Access Token
49
</TabsTrigger>
50
</TabsList>
51
<div className="border-gray-200 dark:border-gray-800 pt-1 border-b"></div>
52
<TabsContent value="ssh_key" className="space-y-4 mt-4">
53
{!hasSSHKey && (
54
<Alert type="warning" className="whitespace-normal">
55
You don't have any public SSH keys in your Gitpod account. You can{" "}
56
<Link to={settingsPathSSHKeys} className="gp-link">
57
add a new public key
58
</Link>
59
, or use a generated access token.
60
</Alert>
61
)}
62
63
<p className="text-gray-500 whitespace-normal text-base">
64
<span>
65
The following shell command can be used to SSH into this workspace with an{" "}
66
<Link to={settingsPathSSHKeys} className="gp-link">
67
SSH key
68
</Link>
69
.
70
</span>
71
</p>
72
<InputWithCopy className="my-2" value={sshKeyCommand} tip="Copy SSH Command" />
73
</TabsContent>
74
<TabsContent value="access_token" className="space-y-4 mt-4">
75
<Alert type="warning" className="whitespace-normal">
76
<b>Anyone</b> on the internet with this command can access the running workspace. The command
77
includes a generated access token that resets on every workspace restart.
78
</Alert>
79
<p className="text-gray-500 whitespace-normal text-base">
80
The following shell command can be used to SSH into this workspace.
81
</p>
82
<InputWithCopy className="my-2" value={sshAccessTokenCommand} tip="Copy SSH Command" />
83
</TabsContent>
84
</Tabs>
85
</>
86
);
87
}
88
89
export default function ConnectToSSHModal(props: {
90
workspaceId: string;
91
ownerToken: string;
92
ideUrl: string;
93
onClose: () => void;
94
}) {
95
return (
96
<Modal hideDivider visible onClose={props.onClose}>
97
<ModalHeader>Connect via SSH</ModalHeader>
98
<ModalBody>
99
<SSHView workspaceId={props.workspaceId} ownerToken={props.ownerToken} ideUrl={props.ideUrl} />
100
</ModalBody>
101
<ModalFooter>
102
<Button variant="secondary" onClick={() => props.onClose()}>
103
Close
104
</Button>
105
</ModalFooter>
106
</Modal>
107
);
108
}
109
110