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-get.go
2498 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/v1"
10
"github.com/spf13/cobra"
11
)
12
13
var publicApiWorkspacesGetCmd = &cobra.Command{
14
Use: "get <workspace-id>",
15
Short: "Retrieve details about a workspace by 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.Log.WithError(err).Fatal()
23
}
24
25
service := v1.NewWorkspaceServiceClient(conn)
26
27
log.Log.Debugf("Retrieving workspace ID: %s", workspaceID)
28
resp, err := service.GetWorkspace(cmd.Context(), &v1.GetWorkspaceRequest{WorkspaceId: workspaceID})
29
if err != nil {
30
log.WithError(err).Fatalf("failed to retrieve workspace (ID: %s)", workspaceID)
31
return
32
}
33
34
tpl := `ID: {{ .Workspace.Id }}
35
OrganizationID: {{ .Workspace.OrganizationId }}
36
ContextURL: {{ .Workspace.ContextUrl }}
37
InstanceID: {{ .Workspace.Status.InstanceId }}
38
InstanceStatus: {{ .Workspace.Status.Phase.Name }}
39
`
40
err = getOutputFormat(tpl, "{..result.workspace_id}").Print(resp)
41
if err != nil {
42
log.Fatal(err)
43
}
44
},
45
}
46
47
func init() {
48
publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesGetCmd)
49
}
50
51