Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/public-api-workspaces-ownertoken.go
2496 views
1
// Copyright (c) 2022 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/gitpod-io/gitpod/common-go/log"
9
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
10
"github.com/spf13/cobra"
11
)
12
13
var publicApiWorkspacesOwnertokenCmd = &cobra.Command{
14
Use: "ownertoken <workspace-id>",
15
Short: "Retrieve the owner token for a given workspace ID",
16
Args: cobra.ExactArgs(1),
17
Run: func(cmd *cobra.Command, args []string) {
18
workspaceID := args[0]
19
20
conn, err := newPublicAPIConn()
21
if err != nil {
22
log.WithError(err).Fatal()
23
}
24
25
service := v1.NewWorkspacesServiceClient(conn)
26
27
log.Debugf("Retrieving workspace owner token for %s", workspaceID)
28
resp, err := service.GetOwnerToken(cmd.Context(), &v1.GetOwnerTokenRequest{WorkspaceId: workspaceID})
29
if err != nil {
30
log.WithError(err).Fatalf("failed to retrieve owner token (ID: %s)", workspaceID)
31
return
32
}
33
34
tpl := `{{ .Token }}`
35
err = getOutputFormat(tpl, "{..token}").Print(resp)
36
if err != nil {
37
log.Fatal(err)
38
}
39
},
40
}
41
42
func init() {
43
publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesOwnertokenCmd)
44
}
45
46