Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/cmd/terminal.go
2498 views
1
// Copyright (c) 2020 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
"time"
11
12
"github.com/spf13/cobra"
13
"google.golang.org/grpc"
14
"google.golang.org/grpc/credentials/insecure"
15
16
"github.com/gitpod-io/gitpod/common-go/log"
17
"github.com/gitpod-io/gitpod/supervisor/pkg/supervisor"
18
)
19
20
var terminalCmd = &cobra.Command{
21
Use: "terminal",
22
Short: "interacts with supervisor's terminal mux",
23
Hidden: true,
24
}
25
26
func init() {
27
rootCmd.AddCommand(terminalCmd)
28
}
29
30
func dialSupervisor() *grpc.ClientConn {
31
cfg, err := supervisor.GetConfig()
32
if err != nil {
33
log.WithError(err).Fatal("cannot get config")
34
}
35
36
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
37
defer cancel()
38
url := fmt.Sprintf("localhost:%d", cfg.APIEndpointPort)
39
conn, err := grpc.DialContext(ctx, url, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
40
if err != nil {
41
log.WithError(err).Fatal("cannot connect to supervisor")
42
}
43
44
// TODO(cw): devise some means to properly close the connection
45
46
return conn
47
}
48
49