/** * Copyright (c) 2022 Gitpod GmbH. All rights reserved. * Licensed under the GNU Affero General Public License (AGPL). * See License-AGPL.txt in the project root for license information. */ import { useEffect, useState } from "react"; import Modal from "../components/Modal"; import Tooltip from "../components/Tooltip"; import copy from "../images/copy.svg"; import Alert from "../components/Alert"; import TabMenuItem from "../components/TabMenuItem"; import { settingsPathSSHKeys } from "../settings/settings.routes"; import { getGitpodService } from "../service/service"; function InputWithCopy(props: { value: string; tip?: string; className?: string }) { const [copied, setCopied] = useState(false); const copyToClipboard = (text: string) => { const el = document.createElement("textarea"); el.value = text; document.body.appendChild(el); el.select(); try { document.execCommand("copy"); } finally { document.body.removeChild(el); } setCopied(true); setTimeout(() => setCopied(false), 2000); }; const tip = props.tip ?? "Click to copy"; return (
copyToClipboard(props.value)}>
copy icon
); } interface SSHProps { workspaceId: string; ownerToken: string; ideUrl: string; } function SSHView(props: SSHProps) { const [hasSSHKey, setHasSSHKey] = useState(true); const [selectSSHKey, setSelectSSHKey] = useState(true); useEffect(() => { getGitpodService() .server.hasSSHPublicKey() .then((d) => { setHasSSHKey(d); }) .catch(console.error); }, []); const host = props.ideUrl.replace(props.workspaceId, props.workspaceId + ".ssh"); const sshAccessTokenCommand = `ssh '${props.workspaceId}#${props.ownerToken}@${host}'`; const sshKeyCommand = `ssh '${props.workspaceId}@${host}'`; return ( <>
{ setSelectSSHKey(true); }} /> { setSelectSSHKey(false); }} />
{!selectSSHKey && ( Anyone on the internet with this command can access the running workspace. The command includes a generated access token that resets on every workspace restart. )} {!hasSSHKey && selectSSHKey && ( You don't have any public SSH keys in your Gitpod account. You can{" "} add a new public key , or use a generated access token. )}

{!selectSSHKey ? ( "The following shell command can be used to SSH into this workspace." ) : ( <> The following shell command can be used to SSH into this workspace with a{" "} ssh key . )}

); } export default function ConnectToSSHModal(props: { workspaceId: string; ownerToken: string; ideUrl: string; onClose: () => void; }) { return ( props.onClose()}> Close } visible={true} onClose={props.onClose} >
); }