Skip to content

Commit b19ad65

Browse files
committed
[gp-cli] add command to extend workspace timeout
1 parent 1dfc504 commit b19ad65

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed
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+
"context"
9+
"time"
10+
11+
gitpod "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
12+
serverapi "github.com/gitpod-io/gitpod/gitpod-protocol"
13+
"github.com/sourcegraph/jsonrpc2"
14+
"github.com/spf13/cobra"
15+
)
16+
17+
// extendTimeoutCmd extend timeout of current workspace
18+
var extendTimeoutCmd = &cobra.Command{
19+
Use: "extend",
20+
Short: "Extend timeout of current workspace",
21+
Run: func(cmd *cobra.Command, args []string) {
22+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
23+
defer cancel()
24+
wsInfo, err := gitpod.GetWSInfo(ctx)
25+
if err != nil {
26+
fail(err.Error())
27+
}
28+
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
29+
"function:setWorkspaceTimeout",
30+
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
31+
})
32+
if err != nil {
33+
fail(err.Error())
34+
}
35+
var tmp serverapi.WorkspaceTimeoutDuration = serverapi.WorkspaceTimeoutDuration180m
36+
if _, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, &tmp); err != nil {
37+
if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {
38+
fail("Cannot extend workspace timeout for current plan, please upgrade your plan")
39+
}
40+
fail(err.Error())
41+
}
42+
},
43+
}
44+
45+
func init() {
46+
timeoutCmd.AddCommand(extendTimeoutCmd)
47+
}

components/gitpod-cli/cmd/timeout.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// timeoutCmd commands collection
12+
var timeoutCmd = &cobra.Command{
13+
Use: "timeout",
14+
Short: "A collection of commands for workspace timeout",
15+
}
16+
17+
func init() {
18+
rootCmd.AddCommand(timeoutCmd)
19+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 protocol
6+
7+
const (
8+
9+
// 400 Unauthorized
10+
BAD_REQUEST = 400
11+
12+
// 401 Unauthorized
13+
NOT_AUTHENTICATED = 401
14+
15+
// 402 Payment Required
16+
NOT_ENOUGH_CREDIT = 402
17+
18+
// 403 Forbidden
19+
PERMISSION_DENIED = 403
20+
21+
// 404 Not Found
22+
NOT_FOUND = 404
23+
24+
// 409 Conflict (e.g. already existing)
25+
CONFLICT = 409
26+
27+
// 410 No User
28+
SETUP_REQUIRED = 410
29+
30+
// 429 Too Many Requests
31+
TOO_MANY_REQUESTS = 429
32+
33+
// 430 Repository not whitelisted (custom status code)
34+
REPOSITORY_NOT_WHITELISTED = 430
35+
36+
// 460 Context Parse Error (custom status code)
37+
CONTEXT_PARSE_ERROR = 460
38+
39+
// 461 Invalid gitpod yml
40+
INVALID_GITPOD_YML = 461
41+
42+
// 450 Payment error
43+
PAYMENT_ERROR = 450
44+
45+
// 470 User Blocked (custom status code)
46+
USER_BLOCKED = 470
47+
48+
// 471 User Deleted (custom status code)
49+
USER_DELETED = 471
50+
51+
// 472 Terms Acceptance Required (custom status code)
52+
USER_TERMS_ACCEPTANCE_REQUIRED = 472
53+
54+
// 480 Plan does not allow private repos
55+
PLAN_DOES_NOT_ALLOW_PRIVATE_REPOS = 480
56+
57+
// 481 Professional plan is required for this operation
58+
PLAN_PROFESSIONAL_REQUIRED = 481
59+
60+
// 485 Plan is only allowed for students
61+
PLAN_ONLY_ALLOWED_FOR_STUDENTS = 485
62+
63+
// 490 Too Many Running Workspace
64+
TOO_MANY_RUNNING_WORKSPACES = 490
65+
66+
// 500 Internal Server Error
67+
INTERNAL_SERVER_ERROR = 500
68+
69+
// 501 EE Feature
70+
EE_FEATURE = 501
71+
72+
// 555 EE License Required
73+
EE_LICENSE_REQUIRED = 555
74+
75+
// 601 SaaS Feature
76+
SAAS_FEATURE = 601
77+
78+
// 610 Invalid Team Subscription Quantity
79+
TEAM_SUBSCRIPTION_INVALID_QUANTITY = 610
80+
81+
// 620 Team Subscription Assignment Failed
82+
TEAM_SUBSCRIPTION_ASSIGNMENT_FAILED = 620
83+
84+
// 630 Snapshot Error
85+
SNAPSHOT_ERROR = 630
86+
87+
// 640 Headless logs are not available (yet)
88+
HEADLESS_LOG_NOT_YET_AVAILABLE = 640
89+
)

0 commit comments

Comments
 (0)