Skip to content

[gp-cli] add command to extend workspace timeout #10619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions components/gitpod-cli/cmd/timeout-extend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"context"
"time"

gitpod "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
serverapi "github.com/gitpod-io/gitpod/gitpod-protocol"
"github.com/sourcegraph/jsonrpc2"
"github.com/spf13/cobra"
)

// extendTimeoutCmd extend timeout of current workspace
var extendTimeoutCmd = &cobra.Command{
Use: "extend",
Short: "Extend timeout of current workspace",
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
wsInfo, err := gitpod.GetWSInfo(ctx)
if err != nil {
fail(err.Error())
}
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
"function:setWorkspaceTimeout",
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
})
if err != nil {
fail(err.Error())
}
var tmp serverapi.WorkspaceTimeoutDuration = serverapi.WorkspaceTimeoutDuration180m
if _, err := client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, &tmp); err != nil {
if err, ok := err.(*jsonrpc2.Error); ok && err.Code == serverapi.PLAN_PROFESSIONAL_REQUIRED {
fail("Cannot extend workspace timeout for current plan, please upgrade your plan")
}
fail(err.Error())
}
},
}

func init() {
timeoutCmd.AddCommand(extendTimeoutCmd)
}
19 changes: 19 additions & 0 deletions components/gitpod-cli/cmd/timeout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"github.com/spf13/cobra"
)

// timeoutCmd commands collection
var timeoutCmd = &cobra.Command{
Use: "timeout",
Short: "A collection of commands for workspace timeout",
}

func init() {
rootCmd.AddCommand(timeoutCmd)
}
89 changes: 89 additions & 0 deletions components/gitpod-protocol/go/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package protocol

const (

// 400 Unauthorized
BAD_REQUEST = 400

// 401 Unauthorized
NOT_AUTHENTICATED = 401

// 402 Payment Required
NOT_ENOUGH_CREDIT = 402

// 403 Forbidden
PERMISSION_DENIED = 403

// 404 Not Found
NOT_FOUND = 404

// 409 Conflict (e.g. already existing)
CONFLICT = 409

// 410 No User
SETUP_REQUIRED = 410

// 429 Too Many Requests
TOO_MANY_REQUESTS = 429

// 430 Repository not whitelisted (custom status code)
REPOSITORY_NOT_WHITELISTED = 430

// 460 Context Parse Error (custom status code)
CONTEXT_PARSE_ERROR = 460

// 461 Invalid gitpod yml
INVALID_GITPOD_YML = 461

// 450 Payment error
PAYMENT_ERROR = 450

// 470 User Blocked (custom status code)
USER_BLOCKED = 470

// 471 User Deleted (custom status code)
USER_DELETED = 471

// 472 Terms Acceptance Required (custom status code)
USER_TERMS_ACCEPTANCE_REQUIRED = 472

// 480 Plan does not allow private repos
PLAN_DOES_NOT_ALLOW_PRIVATE_REPOS = 480

// 481 Professional plan is required for this operation
PLAN_PROFESSIONAL_REQUIRED = 481

// 485 Plan is only allowed for students
PLAN_ONLY_ALLOWED_FOR_STUDENTS = 485

// 490 Too Many Running Workspace
TOO_MANY_RUNNING_WORKSPACES = 490

// 500 Internal Server Error
INTERNAL_SERVER_ERROR = 500

// 501 EE Feature
EE_FEATURE = 501

// 555 EE License Required
EE_LICENSE_REQUIRED = 555

// 601 SaaS Feature
SAAS_FEATURE = 601

// 610 Invalid Team Subscription Quantity
TEAM_SUBSCRIPTION_INVALID_QUANTITY = 610

// 620 Team Subscription Assignment Failed
TEAM_SUBSCRIPTION_ASSIGNMENT_FAILED = 620

// 630 Snapshot Error
SNAPSHOT_ERROR = 630

// 640 Headless logs are not available (yet)
HEADLESS_LOG_NOT_YET_AVAILABLE = 640
)