Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/timeout-extend.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
"context"
9
"fmt"
10
"time"
11
12
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
13
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
14
serverapi "github.com/gitpod-io/gitpod/gitpod-protocol"
15
"github.com/sourcegraph/jsonrpc2"
16
"github.com/spf13/cobra"
17
)
18
19
// extendTimeoutCmd extend timeout of current workspace
20
var extendTimeoutCmd = &cobra.Command{
21
Use: "extend",
22
Short: "Extend timeout of current workspace",
23
RunE: func(cmd *cobra.Command, args []string) error {
24
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
25
defer cancel()
26
wsInfo, err := gitpod.GetWSInfo(ctx)
27
if err != nil {
28
return err
29
}
30
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
31
"function:setWorkspaceTimeout",
32
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
33
})
34
if err != nil {
35
return err
36
}
37
defer client.Close()
38
if _, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, time.Minute*180); err != nil {
39
if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {
40
return GpError{OutCome: utils.Outcome_UserErr, Message: "Cannot extend workspace timeout for current plan, please upgrade your plan", ErrorCode: utils.UserErrorCode_NeedUpgradePlan}
41
}
42
return err
43
}
44
fmt.Println("Workspace timeout has been extended to three hours.")
45
return nil
46
},
47
}
48
49
func init() {
50
timeoutCmd.AddCommand(extendTimeoutCmd)
51
}
52
53