Skip to content

Commit 61b3df2

Browse files
csweichelroboquat
authored andcommitted
[gpctl] Add "workspaces list" command
1 parent 705c460 commit 61b3df2

10 files changed

+224
-263
lines changed

dev/gpctl/cmd/api/root.go

Lines changed: 0 additions & 93 deletions
This file was deleted.

dev/gpctl/cmd/api/workspaces-get.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

dev/gpctl/cmd/api/workspaces-ownertoken.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

dev/gpctl/cmd/api/workspaces.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

dev/gpctl/cmd/public-api-workspace.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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/spf13/cobra"
9+
)
10+
11+
var publicApiWorkspacesCmd = &cobra.Command{
12+
Use: "workspaces",
13+
Short: "Interact with workspaces through the public-API",
14+
}
15+
16+
func init() {
17+
publicApiCmd.AddCommand(publicApiWorkspacesCmd)
18+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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/public-api/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.NewWorkspacesServiceClient(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: {{ .Result.WorkspaceId }}
35+
Owner: {{ .Result.OwnerId }}
36+
ContextURL: {{ .Result.Context.ContextUrl }}
37+
`
38+
err = getOutputFormat(tpl, "{..result.workspace_id}").Print(resp)
39+
if err != nil {
40+
log.Fatal(err)
41+
}
42+
},
43+
}
44+
45+
func init() {
46+
publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesGetCmd)
47+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/public-api/v1"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var publicApiWorkspacesListCmd = &cobra.Command{
14+
Use: "list",
15+
Short: "List your workspaces",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
conn, err := newPublicAPIConn()
18+
if err != nil {
19+
log.Log.WithError(err).Fatal()
20+
}
21+
22+
service := v1.NewWorkspacesServiceClient(conn)
23+
24+
resp, err := service.ListWorkspaces(cmd.Context(), &v1.ListWorkspacesRequest{})
25+
if err != nil {
26+
log.WithError(err).Fatal("failed to retrieve workspace list")
27+
return
28+
}
29+
30+
tpl := `ID Owner ContextURL
31+
{{- range .Result }}
32+
{{ .Result.WorkspaceId }} {{ .Result.OwnerId }} {{ .Result.Context.ContextUrl }}
33+
{{ end }}
34+
`
35+
err = getOutputFormat(tpl, "{..id}").Print(resp)
36+
if err != nil {
37+
log.Fatal(err)
38+
}
39+
},
40+
}
41+
42+
func init() {
43+
publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesListCmd)
44+
}

0 commit comments

Comments
 (0)