Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-daemon/cmd/client-init.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
10
"github.com/alecthomas/repr"
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
csapi "github.com/gitpod-io/gitpod/content-service/api"
15
"github.com/gitpod-io/gitpod/ws-daemon/api"
16
)
17
18
// clientInitCmd starts a new workspace
19
var clientInitCmd = &cobra.Command{
20
Use: "init <request.json>",
21
Short: "initialize a workspace",
22
Args: cobra.ExactArgs(0),
23
Run: func(cmd *cobra.Command, args []string) {
24
// fc, err := os.ReadFile(args[0])
25
// if err != nil {
26
// log.WithError(err).Fatal("cannot read init request")
27
// }
28
29
// var initReq api.InitWorkspaceRequest
30
// if err := json.Unmarshal(fc, &initReq); err != nil {
31
// log.WithError(err).Fatal("cannot parse init request")
32
// }
33
34
initReq := api.InitWorkspaceRequest{
35
Id: "foobar",
36
Metadata: &api.WorkspaceMetadata{
37
Owner: "chris",
38
MetaId: "foofoo",
39
},
40
Initializer: &csapi.WorkspaceInitializer{
41
Spec: &csapi.WorkspaceInitializer_Git{
42
Git: &csapi.GitInitializer{
43
RemoteUri: "https://github.com/32leaves/bel",
44
TargetMode: csapi.CloneTargetMode_REMOTE_HEAD,
45
CheckoutLocation: "bel",
46
Config: &csapi.GitConfig{
47
Authentication: csapi.GitAuthMethod_NO_AUTH,
48
},
49
},
50
},
51
},
52
}
53
54
conn, err := getGRPCConnection()
55
if err != nil {
56
log.WithError(err).Fatal("cannot connect")
57
}
58
defer conn.Close()
59
60
client := api.NewWorkspaceContentServiceClient(conn)
61
resp, err := client.InitWorkspace(context.Background(), &initReq)
62
if err != nil {
63
log.WithError(err).Fatal("error during RPC call")
64
}
65
66
repr.Println(resp)
67
},
68
}
69
70
func init() {
71
clientCmd.AddCommand(clientInitCmd)
72
// clientInitCmd.Flags().BoolVar(&startWorkspaceReq.Headless, "headless", false, "start a headless workspace")
73
// clientInitCmd.Flags().StringVarP(&startWorkspaceReq.ServicePrefix, "service-prefix", "p", "", "use a service prefix different from the workspace ID")
74
// clientInitCmd.Flags().StringVar(&startWorkspaceReq.Metadata.Owner, "owner", "foobar", "set the workspace owner")
75
}
76
77