diff --git a/components/gitpod-cli/cmd/timeout-extend.go b/components/gitpod-cli/cmd/timeout-extend.go new file mode 100644 index 00000000000000..b84fbe98f7d605 --- /dev/null +++ b/components/gitpod-cli/cmd/timeout-extend.go @@ -0,0 +1,44 @@ +// Copyright (c) 2021 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/spf13/cobra" +) + +// timeoutExtendCmd represents the timeoutExtendCmd command +var timeoutExtendCmd = &cobra.Command{ + Use: "timeout-extend", + Short: "Extend the timeout of the current workspace to 180 minutes", + Args: cobra.NoArgs, + 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()) + } + _, err = client.SetWorkspaceTimeout(ctx, wsInfo.WorkspaceId, serverapi.WorkspaceTimeoutDuration180m) + if err != nil { + fail(err.Error()) + } + }, +} + +func init() { + rootCmd.AddCommand(timeoutExtendCmd) +} diff --git a/components/gitpod-cli/go.mod b/components/gitpod-cli/go.mod index d2369443c0b156..d184bf6fed0ae5 100644 --- a/components/gitpod-cli/go.mod +++ b/components/gitpod-cli/go.mod @@ -22,6 +22,8 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) +require github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 + require ( github.com/alecthomas/gometalinter v2.0.11+incompatible // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect @@ -39,7 +41,6 @@ require ( github.com/mattn/go-colorable v0.0.9 // indirect github.com/mattn/go-isatty v0.0.4 // indirect github.com/pelletier/go-toml v1.2.0 // indirect - github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 // indirect golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect diff --git a/components/gitpod-cli/go.sum b/components/gitpod-cli/go.sum index dd46008e6516aa..4d82c36658537f 100644 --- a/components/gitpod-cli/go.sum +++ b/components/gitpod-cli/go.sum @@ -169,6 +169,7 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 h1:ajue7SzQMywqRjg2fK7dcpc0QhFGpTR2plWfV4EZWR4= github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0/go.mod h1:r1hZAcvfFXuYmcKyCJI9wlyOPIZUJl6FCB8Cpca/NLE=