Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-daemon/cmd/client.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
"github.com/spf13/cobra"
9
"golang.org/x/xerrors"
10
"google.golang.org/grpc"
11
"google.golang.org/grpc/credentials"
12
"google.golang.org/grpc/credentials/insecure"
13
)
14
15
// clientCmd represents the client command
16
var clientCmd = &cobra.Command{
17
Use: "client",
18
Short: "client that talks to a ws-daemond to initialize workspace",
19
Args: cobra.ExactArgs(1),
20
}
21
22
var clientConfig struct {
23
host string
24
cert string
25
}
26
27
func init() {
28
clientCmd.PersistentFlags().StringVarP(&clientConfig.host, "host", "H", "", "HTTP host to connect to")
29
clientCmd.PersistentFlags().StringVarP(&clientConfig.cert, "tls", "t", "", "TLS certificate when connecting to a secured gRPC endpoint")
30
31
rootCmd.AddCommand(clientCmd)
32
}
33
34
func getGRPCConnection() (*grpc.ClientConn, error) {
35
secopt := grpc.WithTransportCredentials(insecure.NewCredentials())
36
if clientConfig.cert != "" {
37
creds, err := credentials.NewClientTLSFromFile(clientConfig.cert, "")
38
if err != nil {
39
return nil, xerrors.Errorf("could not load tls cert: %w", err)
40
}
41
42
secopt = grpc.WithTransportCredentials(creds)
43
}
44
45
conn, err := grpc.Dial(clientConfig.host, secopt)
46
if err != nil {
47
return nil, err
48
}
49
return conn, nil
50
}
51
52