Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/ssh.go
2498 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"fmt"
10
"os"
11
"time"
12
13
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
14
15
"github.com/spf13/cobra"
16
)
17
18
// todo(ft): distribute this common metadata from the root command to all subcommands to reduce latency
19
var gitpodHost = os.Getenv("GITPOD_HOST")
20
21
// sshCmd represents the ssh command
22
var sshCmd = &cobra.Command{
23
Use: "ssh",
24
Short: "Show the SSH connection command for the current workspace",
25
Long: fmt.Sprintf(`Displays a command with which you can connect to the current workspace.
26
The returned command requires SSH keys to be configured with Gitpod.
27
See %s/user/keys for a guide on setting them up.
28
`, gitpodHost), RunE: func(cmd *cobra.Command, args []string) error {
29
ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
30
defer cancel()
31
32
wsInfo, err := gitpod.GetWSInfo(ctx)
33
if err != nil {
34
return fmt.Errorf("cannot get workspace info: %w", err)
35
}
36
37
sshCommand := fmt.Sprintf("ssh '%s@%s.ssh.%s'", wsInfo.WorkspaceId, wsInfo.WorkspaceId, wsInfo.WorkspaceClusterHost)
38
fmt.Println(sshCommand)
39
return nil
40
},
41
}
42
43
func init() {
44
rootCmd.AddCommand(sshCmd)
45
}
46
47