Skip to content

Commit 3225597

Browse files
Andrew Farriesroboquat
Andrew Farries
authored andcommitted
Add gp timeout show command
1 parent 3e7c250 commit 3225597

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
"context"
9+
"fmt"
10+
"time"
11+
12+
gitpod "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
13+
"github.com/spf13/cobra"
14+
)
15+
16+
// showTimeoutCommand shows the workspace timeout
17+
var showTimeoutCommand = &cobra.Command{
18+
Use: "show",
19+
Short: "Show the current workspace timeout",
20+
Run: func(_ *cobra.Command, _ []string) {
21+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
22+
defer cancel()
23+
wsInfo, err := gitpod.GetWSInfo(ctx)
24+
if err != nil {
25+
fail(err.Error())
26+
}
27+
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
28+
"function:getWorkspaceTimeout",
29+
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
30+
})
31+
if err != nil {
32+
fail(err.Error())
33+
}
34+
35+
res, err := client.GetWorkspaceTimeout(ctx, wsInfo.WorkspaceId)
36+
if err != nil {
37+
fail(err.Error())
38+
}
39+
40+
// Try to use `DurationRaw` but fall back to `Duration` in case of
41+
// old server component versions that don't expose it.
42+
if res.DurationRaw != "" {
43+
fmt.Println(res.DurationRaw)
44+
} else {
45+
fmt.Println(res.Duration)
46+
}
47+
},
48+
}
49+
50+
func init() {
51+
timeoutCmd.AddCommand(showTimeoutCommand)
52+
}

0 commit comments

Comments
 (0)