Path: blob/main/components/gitpod-cli/cmd/timeout-extend.go
2498 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"8"fmt"9"time"1011"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"12"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"13serverapi "github.com/gitpod-io/gitpod/gitpod-protocol"14"github.com/sourcegraph/jsonrpc2"15"github.com/spf13/cobra"16)1718// extendTimeoutCmd extend timeout of current workspace19var extendTimeoutCmd = &cobra.Command{20Use: "extend",21Short: "Extend timeout of current workspace",22RunE: func(cmd *cobra.Command, args []string) error {23ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)24defer cancel()25wsInfo, err := gitpod.GetWSInfo(ctx)26if err != nil {27return err28}29client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{30"function:setWorkspaceTimeout",31"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",32})33if err != nil {34return err35}36defer client.Close()37if _, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, time.Minute*180); err != nil {38if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {39return GpError{OutCome: utils.Outcome_UserErr, Message: "Cannot extend workspace timeout for current plan, please upgrade your plan", ErrorCode: utils.UserErrorCode_NeedUpgradePlan}40}41return err42}43fmt.Println("Workspace timeout has been extended to three hours.")44return nil45},46}4748func init() {49timeoutCmd.AddCommand(extendTimeoutCmd)50}515253